/**
 * Composite is a structural design pattern that allows
 * composing objects into a tree-like structure and work
 * with the it as if it was a singular object.
 */ export abstract class Component { public composite : boolean = false ; public abstract operation ( ) ; } export class Leaf extends Component { public operation ( ) { return 'Leaf' ; } } export class Composite extends Component { protected children : Set < Component > = new Set ( ) ; public add ( component ) { this . children . add ( component ) ; } public remove ( component ) { this . children . delete ( component ) ; } public operation ( ) { const result = [ ] ; this . children . forEach ( ( child ) => { result . push ( child . operation ( ) ) ; } ) ; return result . join ( ' ' ) ; } }