/**
 * Strategy is a behavioral design pattern that defines
 * a family of algorithms, put each of them into a separate
 * class, and make their objects interchangeable.
 */ interface Strategy { execute ( a , b ) : number ; } export class AddStrategy implements Strategy { execute ( a , b ) { return a + b ; } } export class SubtractStrategy implements Strategy { execute ( a , b ) { return a - b ; } } export class Context { private strategy : Strategy ; constructor ( strategy ) { this . strategy = strategy ; } public setStrategy ( strategy ) { this . strategy = strategy ; } public execute ( a , b ) { return this . strategy . execute ( a , b ) ; } }