Decorator Pattern
noun
say it: “DEK-uh-ray-ter PAT-urn” /ˈdɛkəˌreɪtər ˈpætərn/
A design pattern that adds a feature to an object by wrapping it in another object with the same interface.
What is Decorator Pattern?
The Decorator pattern wraps an object to add behavior without changing its class, like adding whipped cream to a coffee order. Wrappers can be stacked.
ICoffee order = new WhippedCream(new ExtraShot(new BasicCoffee()));
Console.WriteLine(order.Cost());
In a sentence
- “With the Decorator pattern, counting SkyCast's calls was one more layer, not four more subclasses.”
Level: Freelancer · More OOP terms at this level
Updated