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 閱讀(106) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 浮山县| 元阳县| 池州市| 山阴县| 大连市| 辽中县| 呈贡县| 昌图县| 大竹县| 太湖县| 平乐县| 大宁县| 常州市| 剑阁县| 谢通门县| 钟山县| 吐鲁番市| 兖州市| 九龙坡区| 吴忠市| 乐亭县| 额济纳旗| 宿州市| 武安市| 长武县| 治县。| 安乡县| 鲁山县| 讷河市| 西吉县| 郁南县| 沛县| 扎囊县| 广丰县| 杂多县| 台山市| 海兴县| 通道| 明水县| 呼和浩特市| 行唐县|