State模式定义:允许对象在内部状态改变时改变自己的行为,就像改变了对象的类。
Strategy模式定义:定义了算法簇,分别封装起来,让他们之间可以互相替换,此模式让算法的的变化独立于使用算法的客户。
这2个模式可以说从命名上就能看出其专注的问题点!
状态模式专注于对象的状态,对状态进行了行为上的封装,因此,不同的状态,所执行的操作时完全不同的,当有新的状态出现时,我们不得不增加类来满足业务的需要,而状态的改变对操作者是透明的,操作者不需要关注当前状态会执行什么,因为状态告诉操作者:我是足够聪明的,相信我!
策略模式不会去关注对象的状态,而主要考虑我需要什么样的操作,这些操作有哪些的共通的,那么我就把这些共通的行为进行对象化,产生行为类,自己去管理这些行为类,需要做什么样的事情,就持有该行为类,执行该类的共通方法。
状态模式由状态类管理状态的改变,而策略模式由用户来决定使用什么策略!
个人浅显的观点,不足的地方,请大家多指教,一起讨论!
分享到:
相关推荐
This paper presents a pseudospectral strategy for lane change maneuvers of automated vehicles on the highway. This strategy can optimize the longitudinal and lateral control simultaneously to account ...
HIT strategy About North Caroline State in US
Near-Optimal Resilient Control Strategy Design for State-Saturated Networked Systems Under Stochastic Communication Protocol
mule基本节点解释汇总 .... ... <default-service-exception-strategy> ... </default-service-exception-... <service name="GreeterUMO2" initialState="stopped"> ... </mule>
In the absence of a study, the station believes the new advertising strategy has a 65% chance of success and a 35% chance of failure at the state level. If successful, the new advertising strategy ...
Singleton, Iterator, Adapter, Decorator, State, Strategy, Factory Method, Observer, Facade and Template Method. Each pattern is introduced with a non-technical example or story that illustrates the ...
Strategy Encapsulates an algorithm inside a class Template Method Defer the exact steps of an algorithm to a subclass Visitor Defines a new operation to a class without change
如:Template Method、Command、Iterator、Observer、State、Strategy、Mediator、Visitor、Interpreter、Memento、Chain of Responsibility。 结构型模式可以让你把类或对象组合到更大的结构中。如:Decorator、...
如:Template Method、Command、Iterator、Observer、State、Strategy、Mediator、Visitor、Interpreter、Memento、Chain of Responsibility。 结构型模式可以让你把类或对象组合到更大的结构中。如:Decorator、...
如:Template Method、Command、Iterator、Observer、State、Strategy、Mediator、Visitor、Interpreter、Memento、Chain of Responsibility。 结构型模式可以让你把类或对象组合到更大的结构中。如:Decorator、...
Strategy 模式 Template Method 模式 Visitor 模式 Guarded Suspension 模式 Producer Consumer 模式 Worker Thread 模式 Thread-Per-Message 模式 Future 模式 Read-Write-Lock 模式 Two-phase ...
You will also learn to apply state-of-the-art research in software engineering, strategy, and evolutionary biology to leverage ecosystem dynamics unique to platforms. ☆ 出版信息:☆ [作者信息] ...
■Chapter 9: Behavioral Patterns: State, Strategy, Template Method, and Visitor ■Chapter 10: Patterns of Enterprise Application Architecture: Repository, Unit of Work, Lazy Load, and Service Layer ...
:rocket: 上 创建人:Immer ... 这意味着您可以通过修改数据来与数据进行交互,从而使数据的所有优点保持不变,即nextState是currentState的深层且不变的副本。 使用例 结果 BaseState不会更改,
• Strategy • Template Method • Visitor • Discussion of Behavioral Patterns Conclusion • What to Expect from Design Patterns • A Brief History • The Pattern Community • An Invitation ...
State University of New York at Albany Because of current federal legislation, educators must assess children with possible handicapping conditions and plan an individual education program for each...
def build_town ( state ): print state return [( 'build_barracks_task' ,),( 'build_watchtower_task' ,)] 领域 有两种类型的资源: 金子 木头 有3种类型的建筑: 军营 岗楼 屋 有工人(苦工),他们需要...
软件设计模式,行为型模式:ChainOf Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template method Visitor
communication strategy, considering communication delay, a platoon control law is proposed based on sampled state information, which allows the weights of state errors to vary along the platoon. ...
AbstractFactory Adapter Brige Builder ChainOfResponsibility Command Composite Decorator Facade Factory FlyWeight Interpreter Iterator Mediator ...State Strategy TemplateMethod Visitor