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

举动型——Strategy(策略模式)

2012-10-31 
行为型——Strategy(策略模式)???package strategypublic abstract class RepTempRule {public abstract vo

行为型——Strategy(策略模式)

?

?举动型——Strategy(策略模式)

?

package strategy;public abstract class RepTempRule {public abstract void replace() throws Exception;}

?

package strategy;public class RepTempRuleOne extends RepTempRule {public void replace() throws Exception {System.out.println("RepTempRuleOne");}}

?

package strategy;public class RepTempRuleTwo extends RepTempRule {public void replace() throws Exception {System.out.println("RepTempRuleTwo");}}

?

package strategy;public class TestStrategy {RepTempRule rule = null;public TestStrategy(RepTempRule rule){this.rule = rule;}public void doStrategy(){try {rule.replace();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static void main(String[] args) {RepTempRule tempRule = new RepTempRuleOne();TestStrategy test = new TestStrategy(tempRule);test.doStrategy();}}

?

热点排行