Decorator Pattern
Medium — good to knowArchitecture
ELI5 — The Vibe Check
You have a Coffee object. You want Coffee with Milk. Coffee with Sugar. Coffee with Milk and Sugar. With inheritance you'd need four classes. With Decorator, you wrap: new Sugar(new Milk(new Coffee())). Each wrapper adds behavior to the thing inside it, like stacking pancakes where each layer adds syrup. Python uses this literally with @decorators.
Real Talk
undefined
When You'll Hear This
undefined
Related Terms
Adapter Pattern
You're in Europe with a US charger. You need an adapter. In code, your app expects a PaymentProcessor with a .pay() method, but the new Stripe SDK uses .
intermediateArchitecture
Proxy Pattern
A Proxy is a stand-in for a real object that controls access to it.
intermediateArchitecture
Strategy Pattern
You're writing a sorter and want to sort by price, name, or date depending on user choice.
intermediateArchitecture