Mid
From PDF
GoF Patterns
Gang of Four Patterns
Decorator Pattern:?
Short answer: The CoffeeDecorator class is abstract, and all concrete decorators (MilkDecorator, SugarDecorator) extend this class. The decorator wraps the SimpleCoffee object (or other decorated objects) and enhances or alters its behavior, like adding extra cost or modifying the description.
Real-world example (ShopNest)
Logging and caching decorators wrap IProductRepository so core SQL code stays clean.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png