For faster navigation, this Iframe is preloading the Wikiwand page for 适配器模式.

适配器模式

此条目没有列出任何参考或来源。 (2020年7月2日)维基百科所有的内容都应该可供查证。请协助补充可靠来源改善这篇条目。无法查证的内容可能会因为异议提出而被移除。

设计模式中,适配器模式(英语:adapter pattern)有时候也称包装样式或者包装(英语:wrapper)。将一个的接口转接成用户所期待的。一个适配使得因接口不兼容而不能在一起工作的类能在一起工作,做法是将类自己的接口包裹在一个已存在的类中。

结构

有两种类型的适配器模式:

对象适配器模式

在这种适配器模式中,适配器容纳一个它包裹的类的实例。在这种情况下,适配器调用被包裹对象的物理实体。

统一建模语言(UML)表示的对象适配器模式。 The adaptor hides the adaptee's interface from the client.
Lepus3建模语言英语Lepus3表示的对象适配器模式。

类适配器模式

这种适配器模式下,适配器继承自己实现的类(一般多重继承)。

用统一建模语言(UML)表示的类适配器模式。


{{bottomLinkPreText}} {{bottomLinkText}}
适配器模式
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?