问题
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 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.
来源:https://stackoverflow.com/questions/46517113/why-do-the-references-in-a-decorator-and-in-a-proxy-point-to-their-subjects-int