Thinking in Design Pattern

Principle in DP:

1. Everything is an object.

    1.1 所有的模式都是围绕对象展开. 解决方案大体可分2类:

    1.1.1 通过Add type, override virtual method, 来适应改变. Factory, decorator 等等众多模式都是如此.

    1.1.2 简单创建对象, 通过对象的自管理来处理变化. Facade, mediator 些许模式如此. 

2. Encapsulating variation.

    When an aspect of a program changes frequently, defining an object that encapsulates that aspect[1].

3. To program to an interface, not an implementation

4. To favor object composition ("has") over class inheritance ("is-a").

 

-----------------------------------------------------------------------------------------------------------------

Ref:

[1] Design patterns. GOF. Chapter 5, Page 345.

posted @ 2009-06-02 14:08  Tyrael  阅读(216)  评论(0编辑  收藏  举报