问题描述
我从来没有阅读过清楚的解释,你的是什么?
适配器将给定的类/对象适配到新界面。在前者的情况下,通常采用多重继承。在后一种情况下,对象由适配器对象包裹并传递。我们在这里解决的问题是不兼容的界面。
Facade 更像是一个简单的网关到一组复杂的功能。您可以为客户制作一个黑盒,以减少ie 使界面更简单。
代理提供相同的接口作为代理类,通常会自己做一些内务管理。 (因此,不要复制一个重物体 X
的副本,您可以复制轻量级代理 P
X
并根据需要翻译您的呼叫。)您正在解决客户端不必管理繁重和/或复杂对象的问题。 / p>
装饰器用于向对象添加更多的火药(注意术语对象 - 通常在运行时动态地装饰对象)。您不会隐藏/损害对象的现有界面,但只是在运行时扩展它。
现在您已经参与了装饰器,您将可能想知道为什么强调单词对象 - 一些语言(如Java)根本不允许虚拟继承(即,像C ++那样的多重继承),以允许您在编译时完成此操作。
由于我们拖动了多个继承(和可怕的钻石),您将寻找 mixins - 这是有序线性链接接口来解决多重继承的问题。但是,mixins不会很好地混合。我们最终得到了 traits - 是那些您在C ++中的模板参数中始终弹出窗口的无状态小行为。特质尝试以优雅的方式解决行为的组成和分解问题,而不是为了多重继承或有序链接。
What is the difference between the Facade, Proxy, Adapter, and Decorator design patterns?
I have never read a clear explanation, what's yours?
Adapter adapts a given class/object to a new interface. In the case of the former, multiple inheritance is typically employed. In the latter case, the object is wrapped by a conforming adapter object and passed around. The problem we are solving here is that of non-compatible interfaces.
Facade is more like a simple gateway to a complicated set of functionality. You make a black-box for your clients to worry less i.e. make interfaces simpler.
Proxy provides the same interface as the proxied-for class and typically does some housekeeping stuff on its own. (So instead of making multiple copies of a heavy object X
you make copies of a lightweight proxy P
which in turn manages X
and translates your calls as required.) You are solving the problem of the client from having to manage a heavy and/or complex object.
Decorator is used to add more gunpowder to your objects (note the term objects -- you typically decorate objects dynamically at runtime). You do not hide/impair the existing interfaces of the object but simply extend it at runtime.
Now that you have decorator involved, you will probably want to know why the emphasis on the word object -- some languages (like Java) simply don't allow virtual inheritance (i.e. multiple inheritance as C++ does) to allow you to accomplish this at compile time.
Since we have dragged in multiple inheritances (and the dreaded diamond) you will look out for mixins -- which are ordered linear chaining of interfaces to get around the problems of multiple inheritance. However, mixins don't mix that well. And we end up with traits -- yes those stateless little blobs of behavior that you see pop-up all the time in template parameters in C++. Traits try to address the issues of composition and decomposition of behavior in an elegant manner while not going either for multiple inheritances or ordered chaining.
这篇关于外观,代理,适配器和装饰设计模式之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!