Skip to content

Files

Latest commit

784041b · Jun 29, 2017

History

History

Adapter

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jun 29, 2017
Jun 29, 2017
Jun 29, 2017
Jun 29, 2017

adapter pattern

Background

Adapter pattern is placed under the category of structural design pattern. “Adapter” as the name suggests is the object which lets two mutually incompatible interfaces communicate with each other. But why we want “someone” to adapt to something? You will get an answer if you answer this simple thing- Your laptop charger which you bought in US has flattish pins which easily gets hooked into electrical sockets in US. But when you travel to European countries you may have round holes in the electrical sockets. What do you do then?-Simple buy socket adapters/converters for that.

We use Adapters when incompatible interfaces are involved. Our client object wants to call a method but it is not able to because the interface which our client object can use, is not available with the code which our client object wants to call. Based on what an adapter does the adapter design pattern is also called wrapper pattern, translator pattern. Let’s look at the various participants (objects, interfaces) involved in an adapter pattern.

ITarget: This is the interface which is used by the client to achieve functionality.
Adaptee: This is the functionality which the client desires but its interface is not compatible with the client.
Client: This is the class which wants to achieve some functionality by using the adaptee’s code.
Adapter: This is the class which would implement ITarget and would call the Adaptee code which the client wants to call.

My C# implementation