The patterns are good. The code examples, uh, they're not.
The decorator pattern as it's shown is a really bad implementation, since you're not wrapping functionality but augmenting the results. You are calling the method cost() where you should be doing something like
The patterns are good. The code examples, uh, they're not.
The decorator pattern as it's shown is a really bad implementation, since you're not wrapping functionality but augmenting the results. You are calling the method
cost()
where you should be doing something likenot call the method at the decoration moment.
I'm not going to point out the errors some othe people already pointed out