Summary

Whenever you use a decorator, be careful not to misuse; the number of function calls and complexity might be an issue in some domains. Be sure to determine if a strategy pattern (see GOF), often combined with a composite (also GOF), might be a better choice for altering sets of algorithms.

Here are some other things to think about:

  • If we wished to add a new ChickenBurger type, how much of an impact to the existing system would result? How many toppings would it support? Compare this to the pure inheritance way to solve the problem.

  • When I put together this problem, I considered making the meat patty itself a topping. What are the pros and cons to this approach?

  • One problem with this solution is that the pricing factors are hardcoded into ...

Get Joy of Patterns: Using Patterns for Enterprise Development, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.