设计模式----策略模式
策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换。策略模式让算法独立于使用它的客户而独立变化。(原文:The Strategy Pattern defines a family of algorithms,encapsulates each one,and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.)
?
实例
算法接口:Strategy.java
package strategy;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubContext context;//算法Acontext = new Context(new ConcreteStrategyA());context.contextInterface();//算法Bcontext = new Context(new ConcreteStrategyB());context.contextInterface();}}?