Adapter Design Pattern Example
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 design pattern example. One of the popular and often used patterns in object oriented software development is the adapter pattern. The adapter acts as a wrapper between two objects. Design patterns provide a reliable and easy way to follow proven design principles and to write well structured and maintainable code. The adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients.
Moving on to the concept of design patterns let s explain the adapter design pattern. The adapter could also be thought of as a wrapper. But it can also use builder design pattern and prototype design pattern for creating a product. The adapter design pattern is a structural design pattern that allows two unrelated uncommon interfaces to work together.
This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces. What is adapter design pattern. Mobile battery needs 3 volts to charge but the normal socket produces either 120v us or 240v india. This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces.
This pattern is part of the structural design patterns. It completely depends upon your implementation for creating products. A socket attaches to a ratchet provided that the size of the drive is the. Internally adapter uses factory design pattern for creating objects.
Ado net sqladapter oracleadapter mysqladapter are the best example of adapter pattern. Convert the interface of a class into another interface that clients expect. Adapter pattern works as a bridge between two incompatible interfaces. In other words the adapter pattern makes two incompatible interfaces.
It catches calls for one object and transforms them to format and interface recognizable by the second object. Adapter is a structural design pattern which allows incompatible objects to collaborate. 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.