为什么装饰器和代理中的引用分别指向其主题的界面和具体的? [英] Why do the references in a decorator and in a proxy point to their subject's interface and concrete respectively?

查看:65
本文介绍了为什么装饰器和代理中的引用分别指向其主题的界面和具体的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由四人组成的设计模式

为什么装饰器的引用组件 指向装饰器的装饰器指向装饰器的接口组件

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 a Subject if the RealSubject and Subject 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屋!

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