Adapter Pattern Real Life Example
Socket squarepeg vs roundpeg duck vs.
Adapter pattern real life example. Therefore i want to explain what the adapter is and present a simple real life example on how it can be used. The adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients. You have to use an adapter to make the device s power code plug compatible with the wall socket or power supply. The adapter pattern in real life.
Suppose you like to watch a movie from a movie collection. We will be explaining both of them along with a real world example for a better understanding. This is what the role of an adapter is. To start with this pattern can be implemented in one of two ways or 2 types you can say.
The adapter pattern is one of the most useful patterns in my eyes. By introducing an adapter class that implements the filtercoffeemachine interface and wraps the premiumcoffeemachine class you enable your filtercoffeeapp to use the coffee machine. So instead of discussing how a pattern is defined i like to present why that pattern is introduced to present difference between bridge and adapter pattern. One of the great real life example of adapter design pattern is mobile charger.
The adapter could also be thought of as a wrapper. It works the same way as a real life adapter for example for a power outlet. Also we can find this in memory card usages. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces.
We will be using this example to explain this pattern. Socket wrenches provide an example of the adapter. A real life example could be a case of card reader which acts as an adapter between memory card and a laptop. Turkey worse many don t show multiple adapters for different adaptees someone cited java s arrays aslist as an example of the adapter pattern adapting an interface of only one class to work with another seems a weak example of the gof adapter pattern.
So the mobile charger works as an adapter between mobile charging socket and the wall socket. But before that we will define the components of our system. We need this when we have an ethernet interface on one end and usb on the other. In these situations it s better to apply the adapter pattern.
For this example the adapter class needs to fulfill two tasks. For example consider a usb to ethernet adapter. Most common things related to adapter pattern is the power plugs which requires when using a device from a different country. This pattern is easy to understand as the real world is full of adapters.