-
上下文类 Context:屏蔽上游对策略的直接访问,封装变化
- Strategy属性,构造函数传入
- doAnything:调用Strategy.doSomethng
-
策略接口 Strategy
- doSomething 调用业务逻辑
-
具体策略类 ConcreteStrategy
- doSomething 实现定义具体业务逻辑
strategy = new ConcreteStrategy();
context = new Context(strategy);
context.doAnything();