Adapter Design Pattern In Java With Simple Example
Some of the adapter design pattern example i could easily find in jdk classes are.
Adapter design pattern in java with simple example. The adapter pattern is widely known in software development and used in many programming languages e g java. Example of adapter pattern. Adapter design pattern in java. 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.
Adapter pattern works as a bridge between two incompatible interfaces. Adapter design pattern example in jdk. Design patterns provide a reliable and easy way to follow proven design principles and to write well structured and maintainable code. Now we need to use the same app for our client in the uk that wants the same results but in kilometers per hour km h.
This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces. Uml for adapter pattern. The adapter pattern describes how to convert an object into another object which a clients expects. One of the popular and often used patterns in object oriented software development is the adapter pattern.
Let s understand the example of adapter design pattern by the above uml diagram. 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. Adapter design pattern class diagram. This is the desired interface class which will be used by the clients.
There are the following specifications for the adapter pattern.