适配器模式
在設計模式中,适配器模式(英語:adapter pattern)有时候也称包装样式或者包装(英語:)。将一个类的接口轉接成用户所期待的。一个适配使得因接口不兼容而不能在一起工作的类能在一起工作,做法是将类自己的接口包裹在一个已存在的类中。
结构
有两种类型的适配器模式:
对象适配器模式
在这种适配器模式中,适配器容纳一个它包裹的类的实例。在这种情况下,适配器调用被包裹对象的物理实体。

用统一建模语言(UML)表示的对象适配器模式。 The adaptor hides the adaptee's interface from the client.
_pattern_in_LePUS3.png.webp)
用Lepus3建模语言表示的对象适配器模式。
类适配器模式
这种适配器模式下,适配器继承自己实现的类(一般多重继承)。

用统一建模语言(UML)表示的类适配器模式。
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.