Adapter pattern
The Adapter pattern deals with interfacing two different objects without changing their implementation part. You want to call new object methods using an existing interface but because they don't have something in common, you use a wrapper to connect them. Let's understand this concept in detail.
An Adapter is like a wrapper. It wraps one object in a new structure or interface that can be used in a client that expects that interface. This way, you can expand the usage of a particular object and make it work across incompatible interfaces.
We explain the fundamental reasons to use this pattern next.
When to use Adapter
In general terms, you want to use this pattern whenever you want to solve the following problems:
- You have a client that expects an interface of type A but you have an object that implements type B: You don't want to implement interface A for the second object mainly because it is not suitable and because you cannot...