Deck the halls — The Design Pattern

Sameeha Rahman
5 min readJul 13, 2019

I’m gonna give you a small scenario.

Say you own a coffee shop, and like any newbie, start out with just two types of plain coffee, the house blend, and dark roast. In your billing system, there was one class for the different coffee blends, which inherits the beverage abstract class. People actually start to come by and have your wonderful (albeit bitter😖) coffee. Then there are the coffee newbs that, God forbid, want sugar or milk. Such travesty to coffee!! 😱😱

Now you need to have those two add-ons as well, both to the menu, and unfortunately on the billing system. Originally, your IT guy will make a subclass for both coffees, one including sugar, the other milk. Then, since customers are always right, one says these dreaded words;

“Can I get a milk coffee, with sugar, please?”

😒😒😒

There goes your billing system laughing in your face again. Well, back to the drawing board….

The IT guy then adds milk coffee with sugar as another subclass to each parent coffee class. The rest of the month is smooth sailing, people lining up to have your coffee, you actually making money. 💸💰

But wait, there’s more!

The world is against you once again. A competitor opens up across the street, with not just 4 types of coffee, but more than 10 add-ons as well! 😤

You buy all those and more, to sell better coffee yourself, and just then remember that you…

--

--

Sameeha Rahman

Front End Developer at Switchd Ltd. | MSc in Computer Science @ QMUL (2022)