0

The two patterns' uml shotted from book Design Patterns Elements of Resuable Object-Oriented Software are listed below:

Proxy pattern uml :

enter image description here

Decorator pattern uml:

enter image description here

my question is why does proxy pattern use the realSubject class instead of composing the Subject interface just like the decorator pattern does.

Andrew ren
  • 41
  • 2
  • Does this answer your question? [Proxy Design Pattern: Association to the Interface or to RealSubject](https://stackoverflow.com/questions/65740160/proxy-design-pattern-association-to-the-interface-or-to-realsubject) A Proxy may instantiate its RealSubject, and therefore would require a concrete dependency. – jaco0646 Dec 08 '21 at 14:37
  • Yes, thanks. I got the matched answer from the link in side your link. Using relation means the proxy manages the delegatee by itself while composition means the delegatee is managed by the client. In other words, the decorator knows little about the delegatee while the proxy knows more. Right? – Andrew ren Dec 09 '21 at 09:57
  • That can be the case, but not always. As I describe in my [answer](https://stackoverflow.com/a/60478875/1371329) quoting the GoF book, composition is not the relationship that distinguishes between these two patterns. – jaco0646 Dec 09 '21 at 15:05

0 Answers0