What Is Adaptor Design Pattern In Java
Adapter design pattern is one of the structural design pattern and its used so that two unrelated interfaces can work together.
What is adaptor design pattern in java. Java util arrays aslist java io inputstreamreader inputstream returns a reader java io outputstreamwriter outputstream returns a writer that s all for adapter design pattern in. Class diagram of class adapter pattern. The adapter pattern is widely known in software development and used in many programming languages e g java. Adapter pattern works as a bridge between two incompatible interfaces.
Adapter class makes classes with incompatible interfaces work together adapter design pattern is a structural design pattern among the gang of four gof article on gof patterns their types design patterns. Some of the adapter design pattern example i could easily find in jdk classes are. This pattern involves a single class which is responsible to join functionalities of independent or. An example is an adapter that converts the interface of a.
In other words the adapter pattern makes two incompatible interfaces. Adapter pattern example consider a scenario in which there is an app that s developed in the us which returns the top speed of luxury cars in miles per hour mph. Since multiple inheritance is not supported by many languages including java and is associated with many problems we have not shown implementation using class adapter pattern. The adapter pattern describes how to convert an object into another object which a clients expects.
Adapter design pattern example in jdk. Here instead of having an adaptee object inside adapter composition to make use of its functionality adapter inherits the adaptee. It is often used to make existing classes work with others without modifying their source code. Adapter design pattern class diagram.
In software engineering the adapter pattern is a software design pattern also known as wrapper an alternative naming shared with the decorator pattern that allows the interface of an existing class to be used as another interface. This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces. The adapter design pattern is a structural design pattern that allows two unrelated uncommon interfaces to work together. The object that joins these unrelated interface is called an adapter.