Decorator-mönstret lägger dynamiskt till beteende eller ansvar till objekt genom att linda in dem — utan att ändra den ursprungliga klassen. Det ger ett flexibelt alternativ till subklassificering för att utöka funktionalitet, och låter dig komponera beteenden.
Vad Decorator-mönstret gör
DECORATOR → WRAP an object to add behavior, keeping the same interface:
→ the decorator wraps the original, adds its behavior, and delegates to the original
→ you can STACK decorators (wrap a wrapped object) → compose multiple behaviors
→ adds functionality WITHOUT modifying the original class or using subclassing
→ "wrap to extend" — flexible, composable behavior addition
