13.4 状态模式 我们为变化的部分抽象了State接口,把不同的行为封装在相应的状态类中,PaintBoard在执行与状态相关的行为时,把请求转发给当前状态类去执行,这正是状态模式。GoF为状态模式给出的定义是。 Allow an object to alter its behavior when its internal state changes...
12.3 策略模式 上述封装了具体的回家方式的办法,实际上是使用了策略模式,GoF给出的定义是如下。 Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independe...
14.2.2 观察者模式 在这个场景中,股票和投资者之间的关系是1:N的关系,当价格发生一定变化时,股票以广播的方式通知投资者,这正是观察者模式。GoF给出的定义如下。 Define a onetomany dependency between objects so that when one object changes state, all its...