Facade和Adapter Pattern之间有什么区别? [英] What is the difference between the Facade and Adapter Pattern?

查看:253
本文介绍了Facade和Adapter Pattern之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在读这两个定义,看起来完全一样。有人可以指出他们的区别是什么?



谢谢

解决方案

Facade Pattern wiki页面有一个简短的说明。


当包装器
必须尊重特定接口
时,会使用适配器,并且必须支持多态
行为另一方面,当需要一个更简单或
更简单的界面来使用时,会使用一个门面


我听说过你应该考虑到你设计的所有不同的立体声系统的通用遥控器 - 你按开,打开你的有线电视盒,你的接收器,和你的电视。也许这是一个非常漂亮的家庭影院,它也使灯光昏暗,并画出阴影。这是一个Facade - 一个按钮/功能,可以处理更复杂的步骤。



适配器模式只是链接两个不兼容的界面。



编辑:适配器模式(基于注释)的快速比较可能类似于DVI至VGA适配器。现代视频卡通常是DVI,但您有一台旧的VGA显示器。使用可插入视频卡预期DVI输入的适配器,并具有自己的VGA输入,您将可以让旧显示器使用新的视频卡。


I've been reading both definitions and they seem quite the same. Could anyone point out what are their differences?

Thanks

解决方案

The Facade Pattern wiki page has a brief note about this.

"An Adapter is used when the wrapper must respect a particular interface and must support a polymorphic behavior. On the other hand, a facade is used when one wants an easier or simpler interface to work with."

I heard an analogy that you should think of your universal remote control that you've set up to work with all your different stereo systems - you press "on" and it turns on your cable box, your receiver, and your TV. Maybe it's a really fancy home theater and it dims the lights and draws the shades too. That's a Facade - one button/function that takes care of a more complicated set of steps.

The Adapter pattern just links two incompatible interfaces.

EDIT: A quick analogy for the Adapter pattern (based on the comments) might be something like a DVI-to-VGA adapter. Modern video cards are often DVI, but you've got an old VGA monitor. With an adapter that plugs into your video card's expected DVI input, and has its own VGA input, you'll be able to get your old monitor working with your new video card.

这篇关于Facade和Adapter Pattern之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆