您的位置:首页 > 其它

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

2012-12-24 20:50 423 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: