Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decorator Design Pattern

I have been looking at the decorator design pattern (I am new to the subject of design patterns), and I was wondering,

  1. Can a decorator interact with more than one component?
  2. If A is a decorator of component B, can A have operations that B does not have?

Thank you.

like image 386
Nat10 Avatar asked Dec 08 '09 16:12

Nat10


2 Answers

1.) Yes
2.) Yes, that is the main point of a decorator pattern. To add functionality to the object it is decorating.

Decorator Pattern

like image 190
RC. Avatar answered Oct 14 '22 12:10

RC.


Decorator simply adds functionality to the class it decorates. Sorta like icing on the cake. You may decorate more than one component but that sounds more like Facede though I may be wrong. The second question - the wrapper adds functionality but it also can mask it

like image 36
Bostone Avatar answered Oct 14 '22 12:10

Bostone