设计原则

SOLID
1. SRP
   A Single Responsibility Principle
   A class should have one, and only one, reason to change.

2. OCP
   A module should be open for extension but closed for modification.
   polymorphism is a way to implement it.

   Q: what's the difference between static polymorphism and dynamic polymorphism?

3. The Liskov Substitution Principle(LSP)
   Subclasses should be substitutable for their base classes.
  
   we should note the canonical Ellipse/Circle dilemma

4. The Dependency Inversion Principle(DIP)
   Depend upon Abstractions instead of concretions.

   we should note the difference between procedural architecture and OO architecture.

5. The Interface Segregation Principle(ISP)
   Many Client specific interfaces are better than one general purpose interface.
   so we can isolate the individule interface change. we can define interface according to the client category. Any change needed to be made on the existing interfaces, we can add a new interface instead of changing the existing interfaces. So we can avoid the issue of recompilation and redeployment.

6. Principles of Package Architecture
how to group together package

6.1 The Release Reuse Equivalency Principle(REP)
The granule of resue is the granule of release

6.2 The Common Closure Principle(CCP)
Classes that change together, belong together. So the package impact from release will be minimized.

6.3 The Common Reuse Principle(CRP)
Classes that aren't resued together should not be grouped together


6.4 The Acyclic Dependencies Principle(ADP)
The dependencies between packages must not form cycles.

Cycles can be broken in two ways:
1. create a new package
2. make use of the DIP and ISP
add a interface on the user side(who use the function) and the other side implement the interface.

6.5 The Stable Dependencies Principle(SDP)
Depend in the direction of stability.

I(Instability) = Ce/(Ca+Ce)
Ce: Efferent Coupling, outgoing dependencies
Ca: Afferent Coupling, incoming dependencies

So SDP can be rephrased as: Depend upon package whose I metric is lower than yours.

6.6 The Stable Abstractions Principle(SAP)
stable package should be abstract packages.

The stable package maybe hard to change, so it is not flexible; But we can make the stable package abstract, so it is easy to extend.

This is just a restatement of the DIP. That is , the package that the most depended upon should also be the most abstract.

A(Abstractness) = Na/Nc
Na: Number of abstract classes in the package
Nc: Number of classes in the package


7. KISS
Keep it simple and stupid.
Less is more.

8. CoC
Convention over Configuration, e.g. ROR

9. YAGNI
You Ain't Gonna need it. 极限编程中的一个概念,只实现目前需要的功能。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值