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(); }