发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 CQRS 扩展性 并发编程 事件溯源 分布式 SOA

Strategy pattern

    
2004-08-11 17:28
赞助商链接

I have a question about Strategy pattern, I use the example(http://www.jdon.com/designpatterns/designpattern_Strategy.htm) in this website to talk about the question ;

My question is that why Strategy pattern uses the class RepTempRuleSolve (called Context in GOF), I know that RepTempRuleSolve is used by client program to decide which stratgy to use, for example:


RepTempRuleSolve solver=new RepTempRuleSolve(new RepTempRuleTwo());
solver.getNewContext(site,context);


the code here makes the decision to use the strategy implementation RepTempRuleTwo, but why the code does not use the stategy implementation without using RepTempRuleSolve ?

for a new client code example here:


RepTempRule strategy = new RepTempRuleTwo();
strategy.replace(site, context);


In the second example, the client code uses the strategy implementation with using the RepTempRuleSolve; In both examples, the client code also needs to make the decision which strategy implementation to be used, so what's the the benefits of use the class RepTempRuleSolve ?

1
2004-08-13 14:49

RepTempRuleSolver 其实类似中间者,解耦客户端和算法策略选择,RepTempRuleSolver可以使用工厂模式、IoC之类模式实现。

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com