《Agile Software Development》关于Design Principle阅读笔记

 Design Principle:

1、SRP:The Single-Responsibility Principle

     A class should have only one reason to change.

how to use:

Depends how the applicaton is changing.It is not wise to apply the SRP,or any other principle for that matter,if there is no symptom.

心得:SRP的使用存在一个平衡,灵活性和复杂性之间的平衡,是否要按职责分出类来取决于实际需求,有必要分出职责的时候就使用SRP。Rigidity vs Needless Complexity

 

2、OCP:The Open-Closed Principle

     Software entities(class,modules,function,etc) should be open for extension,but closed for modification.

how to use:

Abstraction is the Key!

   When a single change to a program results in a cascade of changes to dependent modules,the design smells of Reigidy.the OCP advises us to refactor the system so that further changes of that kind will not cause more modifications.If the OCP is appled well,then further changes of that kind are achieved by adding new code ,not by changing old code that already works.

  Since closure cannot be complete ,it must be strategic.That is the designer must choose the kinds of changes against which to close his design.

心得:close是不可能完全的,必须懂得预料变化,设计出应对可能变化的Closure。但是这不容易,设计初期大多时候靠猜,有很大的运气成分,要等到变化来的时候才有结果,不要拘泥于形式。

几大方法:1、Fool me once 吃一堑,长一智,积累设计经验 2、Stimulating Change 主动刺激变化产生,早发现,早治疗 3、Using Abstraction to Gain Explicit Closure 运用抽象

 

你可能感兴趣的:(《Agile Software Development》关于Design Principle阅读笔记)