Elliot Chance
Aug 21 · 1 min read

Thank you for the article. It’s clear you have put a lot of thought in to it. This is the second article I’ve read that tries to use real world objects to demonstrate the decorator pattern. A previous article used cakes with various toppings.

I understand the decorator pattern principle but it’s usage in this case isn’t practical and so I believe trying to describe it in this way is ultimately confusing. Nobody would build a billing system where all the menu items were represented as classes. Trying to explain it this way just creates a problem that never existed in the first place, and therefore didn’t need the decorator pattern to solve it.

I’d like to know how the decorator pattern provides any benefit over simply using an interface? Assuming someone were crazy enough to create a class for every type of product, wouldn’t it make far more sense to just have an interface for getCost() and getDescription() ? Multiple products (such as a coffee + sugar + milk) would be an array or similar. Perhaps you have another example that works to solve a real world problem?

Elliot Chance

Written by

I’m a data nerd and TDD enthusiast from Sydney. I love exploring new technologies and working on modern ways to solve age old problems 🤓 elliotchance@gmail.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade