Strategy pattern

    
zujiyun
04-08-11 1 278 1

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
banq
2004-08-13 14:49

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