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

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:

主站蜘蛛池模板: 开化县| 长沙市| 祁门县| 象州县| 平罗县| 平罗县| 扎赉特旗| 灵宝市| 电白县| 利辛县| 特克斯县| 清镇市| 茂名市| 宝丰县| 江西省| 中卫市| 唐海县| 东乌珠穆沁旗| SHOW| 娱乐| 鹤壁市| 合山市| 琼海市| 南华县| 东城区| 日照市| 丹巴县| 合作市| 集安市| 青冈县| 通河县| 临沭县| 沭阳县| 正阳县| 合肥市| 慈利县| 大荔县| 称多县| 马龙县| 宁夏| 张家口市|