Creating interface as your contract with outside world. Use multiple plugs in multiple sockets with the help of an adapter.

Plugs and Sockets of various design

Imagine you are travelling to Europe. And normally you are carrying your phone and your charger. Now while travelling cross-country, you realise your phone charge is low and you immediately went on searching for a power outlet, and you got one. Alas! the outlet design does not match with your charging adapter. But lucky for you, you were carrying an portable universal power outlet to convert European port to multiple Universal Port. Boom, you solved the problem.

Adapter

Well, not quite. You did get the socket needed to port your charging adapter for your phone, but the universal power outlet you were carrying needed an adapter compatible with European socket. So in case you were in the United States, you would have needed an adapter compatible with a US socket.

So despite of any form of layering and/or abstraction, you would need one constant interface to communicate with external world. And that interface will act as contract of your utility to source of power. This does include some amount of coupling, but provide implementation part to evolve and adapt to take any form, i.e., the charging cable can have any adapter as long as it is supported on the outlet.

#programming #design-patterns #firebase

The Adapter Pattern: Create One, Use Many
1.35 GEEK