intermediateDecorator Pattern

Can the order in which decorators are stacked change the final behavior of the wrapped object, and if so, how?

Yes, whenever a decorator's effect isn't simply additive. If every decorator just adds a fixed amount to some value, like a flat topping cost, stacking order doesn't change the final total. But if one decorator applies a percentage change -- a discount or a tax -- while another applies a flat amount, the final result depends on which one runs first, since a percentage calculated before versus after a flat addition produces different numbers. This is worth checking deliberately whenever decorators are combined: additive, order-independent decorators can be stacked freely, but decorators with multiplicative or conditional effects need their stacking order treated as a real design decision.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is a real example from the Java standard library where a class technically satisfies an interface but violates LSP?← Back to all Low-Level Design & Design Patterns questions