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

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:

主站蜘蛛池模板: 丰原市| 伊川县| 冷水江市| 郁南县| 修文县| 陆河县| 汝南县| 仙桃市| 西峡县| 诸暨市| 澎湖县| 秦安县| 招远市| 台州市| 合水县| 江陵县| 昌都县| 石渠县| 安西县| 石景山区| 桃源县| 平江县| 自治县| 阿图什市| 将乐县| 阿坝县| 白朗县| 镶黄旗| 望江县| 天镇县| 南汇区| 井研县| 北宁市| 习水县| 手游| 深圳市| 安仁县| 来凤县| 宜阳县| 连江县| 怀宁县|