Design Pattern - Adapter
Adapter
Definition
Adapter pattern is a software design pattern (also known as wrapper, an alternative naming shared with the decorator pattern) that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.
How Adapter works
Let's look at simple example where we have a hair dryer that can fit to 110V and a cleaner that can fit to 220V. What if we only have 110V port and want to use cleaner? We can use an adapter that can convert 110V to 220V.
Adapter with code
REFERENCE
Comments
Post a Comment