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)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 乌兰察布市| 湖口县| 安庆市| 土默特左旗| 石门县| 蒙城县| 保靖县| 易门县| 富川| 丰台区| 咸宁市| 鹤庆县| 共和县| 隆德县| 武功县| 安康市| 雅安市| 神农架林区| 邵阳县| 平乐县| 郯城县| 高平市| 澄城县| 汶上县| 江川县| 三台县| 达拉特旗| 鄯善县| 治县。| 门源| 来安县| 得荣县| 浮山县| 秭归县| 丁青县| 延庆县| 南漳县| 宜城市| 揭阳市| 鹤峰县| 寿宁县|