1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| interface Component { operation():string }
class ConcreteComponent implements Component { public operation() { return "ConcreateComponent" } }
class Decorator implements Component { constructor(component:Component) { this.component = component } operation() { return this.component.operation() } }
class ConcreteDecoratorA extends Decorator { operation() { return `concreteDecoratorA(${super.operation()})` } } class ConcreteDecoratorB extends Decorator { operation() { return `concreteDecoratorB(${super.operation()})` } } const simple = new ConcreteComponent() const d1 = new ConcreteDecoratorA(simple)
d1.operation()
|