Adapter Factory Design Pattern In Java
Factory pattern is one of the most used design patterns in java.
Adapter factory design pattern in java. There are the following specifications for the adapter pattern. 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. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces. It defines the application specific interface that client uses directly.
In this post i will demonstrate another creational pattern i e. The classes and or objects participating in this pattern are listed as below. This article explains adapter design pattern in java with class diagrams and example code. This is the desired interface class which will be used by the clients.
This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces. Adapter pattern works as a bridge between two incompatible interfaces. The adapter pattern describes how to convert an object into another object which a clients expects. In my previous post singleton design pattern in java we discussed various ways to create an instance of a class such that there can not exist another instance of same class in same jvm.
In software engineering the adapter pattern is a software design pattern that allows the interface of an existing class to be used as another interface. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object. The adapter pattern is widely known in software development and used in many programming languages e g java. The adapter pattern deals with how the classes are composed to form larger.
Let s understand the example of adapter design pattern by the above uml diagram. 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. Factory pattern for creating instances for your classes factory as the name suggests is a place to create some different products. Adapter pattern lets you wrap an otherwise incompatible object in an adapter to make it compatible with another class.
Uml for adapter pattern. Participants of adapter design pattern. 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. In factory pattern we create object without exposing the creation logic to the client and refer to newly created object using a common interface.