2. Quack counting
The NAQ wants to begin gathering statistics on the number of quacks that occur during specific pereiods. And, they want to include honks too. They've asked us to change our model so we can do this. How should we proceed?
We'd like to add the ability to count quacks to the system without having to modify any of the classes. The Decorator pattern seems pretty useful for this.
Now we have the following class diagram:
graphic
We can "wrap" the QuackCounter decorator around any quackable object and find out how many quacks it makes. Not too shabby for just a couple of simple patterns. We're able to isolate behavior and keep our design very flexible.