Why do the references in a decorator and in a proxy point to their subject's interface and concrete respectively?

点点圈 提交于 2019-12-11 10:58:55

问题


From Design Pattern by Gang of Four

Why does the reference component of the decorator Decorator to the decorated point to the interface Component of the decorated,

while the reference realSubject of the proxy Proxy point to the concrete RealSubject?

Thanks.


回答1:


Proxy may point exclusively to its subject's interface. The GoF mentions,

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.



来源:https://stackoverflow.com/questions/46517113/why-do-the-references-in-a-decorator-and-in-a-proxy-point-to-their-subjects-int

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!