为什么装饰器和代理中的引用分别指向其主题的界面和具体的? [英] Why do the references in a decorator and in a proxy point to their subject's interface and concrete respectively?
问题描述
由四人组成的设计模式
为什么装饰器的引用组件
指向装饰器的装饰器
指向装饰器的接口组件
Why does the reference component
of the decorator Decorator
to the decorated point to the interface Component
of the decorated,
而代理<$ c的引用 realSubject
$ c>代理指向具体的 RealSubject
?
while the reference realSubject
of the proxy Proxy
point to the concrete RealSubject
?
谢谢。
推荐答案
代理可能仅指向其主题的界面。 GoF提到,
Proxy may point exclusively to its subject's interface. The GoF mentions,
代理
可能是指如果
。RealSubject
和Subject
接口相同,则为Subject
Proxy
may refer to aSubject
if theRealSubject
andSubject
interfaces are the same.
但是根据实现的不同,代理可以通过调用构造函数来实例化其主题,而构造函数则需要引用一个具体对象。
But depending on implementation, a Proxy may instantiate its subject by calling a constructor, which necessitates referencing a concrete object.
这篇关于为什么装饰器和代理中的引用分别指向其主题的界面和具体的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!