abstract class Strategy{ public abstract void AlgorithmInterface(); } class StrategyA extend Strategy{ public AlgorithmInterface(){ //A實現 }; } class StrategyB extend Strategy{ public AlgorithmInterface(){ //B實現 }; } class StrategyC extend Strategy{ public AlgorithmInterface(){ //C實現 }; } class Context(){ Strategy strategy; public Context(bufferType:Srting){ //能夠搭配簡單工廠模式一塊兒使用 var strategy = null; switch(bufferType){ case "a":strategy = new StrategyA(); case "b":strategy = new StrategyB(); case "c":strategy = new StrategyC(); } this.strategy = buffer; } public ContextInterface(){ this.strategy.AlgorithmInterface(); } } class Main{ Context context = new Context("a"); context.ContextInterface(); }