Skip to content

Latest commit

 

History

History
24 lines (14 loc) · 1.39 KB

File metadata and controls

24 lines (14 loc) · 1.39 KB

In the Name of ALLAH

Adapter Pattern


The Adapter pattern is a structural design pattern that allows objects with incompatible interfaces to work together by creating a middleman called an adapter. The adapter acts as a translator or a bridge between the two incompatible interfaces, enabling them to interact seamlessly.

  • In simple terms, think of an adapter as an electrical plug converter. When you travel to a different country with different electrical outlets, you need an adapter to convert the plug on your device to fit the local outlet.

  • In software development, the Adapter pattern is used when you have two classes or components that cannot directly communicate due to incompatible interfaces. The adapter wraps one of the classes and provides a compatible interface that the other class can understand. This allows the two classes to collaborate without requiring any changes to their existing code.

Problem Statement :

  • A class that would be useful to your application does not implement the interface you require

  • You are designing a class or a framework and you want to ensure it is usable by a wide variety of as-yet-unwritten classes and applications.

  • Adapters are also known as wrappers

Adapter Sample

  • To Convert the interface of a class into another interface clients expect.

Alt text

  • Effective way to implement the Open/ Close Principle