posts - 37,comments - 7,trackbacks - 0
          The class diagrams are essentially the same, but the two patterns differ in their intent.

          With the State Pattern, we have a set of behaviors encapsulated in state objects; at any time the context is delegating to one of those states. Over time, the current state changes across the set of state objects to reflect the internal state of the context, so the context's behavior echanges over time as well. The client usually knows very little, if anything, about the state objects.

          With Strategy, the client usually specifies the strategy object that the context is composed with. Now, while the pattern provides the flexibility to change the strategy object at runtime, often there is a strategy object that is most appropriate for a context object.

          In general, think of the Strategy Pattern as a flexible alternative to subclassing; if you use inheritance to define the behavior of a class, then you're stuck with that behavior even if you need to change it. With Stategy you can change the behavior by composing with a defferent object.

          Think of the State Pattern as an alternative to putting lots of conditionals in your context; by encapsulating the behaviors within state objects, you can simply change the state object in context to change its behavior.
          posted on 2005-08-15 14:13 Dave 閱讀(107) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 会理县| 屯昌县| 东源县| 佛坪县| 社会| 平武县| 新蔡县| 温宿县| 梧州市| 铜山县| 天门市| 扎赉特旗| 延安市| 新民市| 晋江市| 龙川县| 永德县| 黄大仙区| 板桥市| 铜陵市| 界首市| 福建省| 巴林左旗| 卢湾区| 林甸县| 将乐县| 彭水| 泾阳县| 厦门市| 正定县| 武鸣县| 龙江县| 苍溪县| 昌黎县| 晴隆县| 怀柔区| 肇州县| 桂阳县| 昭通市| 包头市| 日照市|