design pattern notes [7] - state,strategy,memento,mediator,and iterator

1131阅读 0评论2012-12-24 hanhuili
分类:项目管理

State allows the object alter its behavior when its internal state changes. This pattern avoids large, multipart conditional statements. It also introduces more classes.
The transition between states is implemented in the subclasses of State.

I think strategy is like visitor. Review it!

The memento does not break encapsulation. It stores snapshot of internal states of an Originator so that the Originator can restore its previous state when a caretaker lets it do that. The caretaker does not know how the memento save Originator's state. It just requests the Originator to store states to or restore states from the memento respectively. The memento simplifies the Originator although sometimes it is expensive.

Mediator encapsulates how a set of objects interact. It promotes loose coupling by keeping objects from referring to each other explicitly.  It is amazing to find that c++ begins to behave like that most of c source codes do.
It centralizes CONTROL!

Iterator provides a way to access an aggregate object sequentially without exposing its underlying representation.

上一篇:MAC OSX Darwin - 设置PATH环境变量
下一篇:完成90%的项目 [3] - 团队文化