bg_image
header

Adapter Pattern

The Adapter Pattern (also known as the Wrapper Pattern) is a design pattern in software development used to address problems when two existing components cannot communicate directly due to incompatible interfaces.

The main goal of the Adapter Pattern is to create a bridge between the two incompatible interfaces without modifying any existing code. It enables collaboration between classes that would otherwise be unable to work together by introducing a specific adapter between them.

There are two main types of adapters:

  1. Class Adapter: This type uses inheritance to adapt the existing target class's interface and connect it with the interface of the Adaptee class.

  2. Object Adapter: This type uses composition and holds a reference to the Adaptee class to provide its functionality through delegation, while exposing the interface of the Target.

A simple example of the Adapter Pattern could be when an existing application uses a specific data source through a particular interface, and you have a new data source that provides a different interface. You could create an adapter that adapts the new data source to the interface of the existing application, allowing it to seamlessly work with the new data source without altering its core logic.

The Adapter Pattern is a flexible and powerful pattern that promotes code reusability and facilitates interoperability between different components. It is commonly used in object-oriented software development.

 


Created 1 Year ago
Backend Design Patterns Frontend Object Oriented Programming Principles Programming Web Development

Leave a Comment Cancel Reply
* Required Field