デコレータパターンは、オブジェクトをラップすることで動的に動作または責任を追加します。元のクラスを変更せずに、サブクラス化の柔軟な代替手段を提供し、動作を合成することができます。
デコレータパターンが行うこと
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
例
coffee = { : , : };
() {
{ : c.() + , : c.() + };
}
() {
{ : c.() + , : c.() + };
}
coffee = ((coffee));
coffee.();
