I am learning Decorator Pattern. It is very powerful pattern, and quite useful. The objective of the pattern is simple, adding(extending) behaviour to objects at runtime without recompiling source code by composition and delegation, hence provides an alternative to subclassing for extending behaviour. However, I read one of the main drawbacks of this pattern and could not quite understand it. Here is the statement:
"People sometimes take a piece of client code that relies on specific types and introduce decorators without thinking through everything. Now, one great thing about me is that you can usually insert decorators transparently and the client never has to know it's dealing with a decorator. But like I said, some code is dependent on specific types and when you start introducing decorators, boom! Bad things happen."
Taken from "Head first design patterns"
What does the author mean by "relying on specific types". If possible, please with real world and simple examples
Aucun commentaire:
Enregistrer un commentaire