While going through Decorator Pattern from Wikipedia 1 and reading pattern from Head First Book . One thing that struck me and is missing from both the sources or i may have missed it.
Why exactly do we need a Decorator Interface ?
- Is it because we need to put all the Concrete Decorators under categorical umbrella.
Suppose if we had only few ( <5) Decorators , Cant we simply sublcass them directly from Component Interface. Terms from wikipedia UML Thus Decorator will be storing the reference of Component Interface Type and it will call the behaviour directly of the Concrete Component after doing adding some more to it. This is the same thing as per the examples from the Head First Book.
Another reason that i can think of Putting a Decorator Interface is to have Runtime support for Adding those Decorators through Factory. This is the only reason that i can make of.
Asking here to wider audience, Is Decorater Interface in Decorator Design Pattern is just for providing Dynamic Support via Factory or there is more to it.
Aucun commentaire:
Enregistrer un commentaire