Uncommon · Knowledge

Adapter pattern

Design pattern in computer program

In software engineering, the 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.

Read more

An example is an adapter that converts the interface of a Document Object Model of an XML document into a tree structure that can be displayed. The adapter design pattern is one of the twenty-three well-known Gang of Four design patterns that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse. The adapter design pattern solves problems like: Often an (already existing) class can not be reused only because its interface does not conform to the interface clients require. The adapter design pattern describes how to solve such problems: The key idea in this pattern is to work through a separate adapter that adapts the interface of an (already existing) class without changing it. Clients don't know whether they work with a target class directly or through an adapter with a class that does not have the target interface. See also the UML class diagram below. An adapter allows two incompatible interfaces to work together. This is the real-world definition for an adapter.

Text: Wikipédia, CC BY-SA 4.0. · Image: Trashtoy (Public domain) ·

Tap to close

Confirmation