首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

设计形式-策略模式

2012-08-25 
设计模式----策略模式策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换。策略

设计模式----策略模式

策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换。策略模式让算法独立于使用它的客户而独立变化。(原文: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();}}
?

热点排行