Adapter Pattern

Adapter pattern is similar to how an electrical adapter lets your laptop work both in the US or UK even though voltages are different.

What is it ?

When two heads of states who don't speak a common language meet, usually a language interpreter sits between the two and translates the conversation, thus enabling communication. The Adapter pattern is similar in that it sits between two incompatible classes that otherwise can't work with eachother and lets them work together. Another example to consider is when one buys electronics from USA and tries to use them in India. The two countries have different power voltages being distributed to consumers and using an electronic appliance from one country in another requires a physical adapter which steps up or down the voltage appropriately. The concept of the software adapter pattern is similar.

Formally, the adapter pattern is defined as allowing incompatible classes to work together by converting the interface of one class into another expected by the clients

.

Get hands-on with 1200+ tech skills courses.