官术网_书友最值得收藏!

The adapter design pattern

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
-GoF Design Patterns: Elements of Reusable Object-Oriented Software

Adapter design patterns come under the structural design pattern, according to this design pattern two incompatible classes work together that couldn't otherwise because of incompatible interfaces. This pattern works as a bridge between two incompatible interfaces. This pattern is used when two inferences of the application are incompatible in their functionalities, but these functionalities need to be integrated as a business requirement.

There are many real-life examples where we can use the adapter pattern. Suppose you have different types of electric plugs such as cylindrical and rectangular plugs, as shown in the following figure. You can use an adapter in between to fit a rectangular plug in a cylindrical socket assuming voltage requirements are met:

主站蜘蛛池模板: 盐亭县| 玉田县| 昌黎县| 应城市| 旅游| 哈尔滨市| 都江堰市| 乌什县| 武安市| 信丰县| 乌兰察布市| 北碚区| 南平市| 北辰区| 秦安县| 荣昌县| 宁陵县| 田东县| 定远县| 山阳县| 吕梁市| 光山县| 玛曲县| 靖安县| 南溪县| 许昌市| 秦安县| 乌兰县| 河池市| 建德市| 公主岭市| 江津市| 礼泉县| 安仁县| 晋州市| 茌平县| 凤翔县| 北票市| 汉寿县| 新化县| 秭归县|