Xiao Peng

My personal blog moves to xiaopeng.me , blogs about design patterns will be synced to here.
肖鹏,ThoughtWorks资深咨询师,目前关注于架构模式、敏捷软件开发等领域,并致力于软件开发最佳实践的推广和应用。
多次为国内大型企业敏捷组织转型提供咨询和培训服务,在大型团队持续集成方面具有丰富的经验。
  博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

Comparing Strategy and State [转载]

Posted on 2006-11-03 11:55  勇敢的鸵鸟  阅读(214)  评论(0编辑  收藏  举报
Comparing Strategy and State

The refactored code consists almost entirely of simple methods in simple classes. This is an advantage in its own right and makes adding new strategies easy. The refactoring relies primarily on the idea of distributing an operation across a related group of classes. In this regard, STRATEGY is identical to STATE. In fact, many developers wonder whether these are really different patterns.

On the one hand, in the real world, strategies (such as recommending a firework) and states (such as a carousel door with a one-touch control button) are clearly different ideas. This real difference leads to different problems in modeling states and strategies. For example, transitions are important when modeling states but usually irrelevant when choosing a strategy. Another difference is that STRATEGY might allow a client to select or to provide a strategy, an idea that rarely applies to STATE. On the other hand, the differences in modeling states and strategies may seem subtle. Certainly, the reliance on polymorphism makes STATE and STRATEGY appear almost identical structurally. Either way, if you decide that these are or are not two separate patterns, you will be in good company.

be in good company: 有很多人相伴,大有人在

转自:http://safari.phptr.com/0201743973/ch23lev1sec3