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) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 潮州市| 廉江市| 上林县| 阿坝县| 家居| 永嘉县| 岳普湖县| 安阳市| 河北区| 阳城县| 崇义县| 萨嘎县| 清原| 岳西县| 安徽省| 湖北省| 长治县| 新乐市| 睢宁县| 黎城县| 绥阳县| 隆安县| 海安县| 泾川县| 宜川县| 蕉岭县| 西乌珠穆沁旗| 清远市| 阿尔山市| 新兴县| 平定县| 泗水县| 鹤庆县| 罗源县| 辰溪县| 射洪县| 遂宁市| 双柏县| 祥云县| 道孚县| 通海县|