几个简单易行的原则

  1. DRY. don’t repeat yourself.

  2. KISS. Keep it simple, stupid

  3. YAGNI. You ain't gonna need it

class design principles

SOLID(wiki, article): SRP, OCP, LSP, ISP, DIP.

  • SRP(wiki, pdf): Single responsibility principle. A class should have one, and only one, reason to change.

  • OCP(wiki, pdf): Open/closed principle. You should be able to extend a classes behavior, without modifying it.

  • LSP(wiki, pdf): Liskov substitution principle. Derived classes must be substitutable for their base classes.

  • ISP(wiki, pdf): Interface segregation principle. Make fine grained interfaces that are client specific.

  • DIP(wiki, pdf): Dependency inversion principle. Depend on abstractions, not on concretions.

package cohesion principles

  • REP(pdf): The Release Reuse Equivalency Principle. The granule of reuse is the granule of release.

  • CCP(pdf): The Common Closure Principle. Classes that change together are packaged together.

  • CRP(pdf): The Common Reuse Principle. Classes that are used together are packaged together.

packages coupling principles

  • ADP(pdf): The Acyclic Dependencies Principle. The dependency graph of packages must have no cycles.

  • SDP(pdf): The Stable Dependencies Principle. Depend in the direction of stability.

  • SAP(pdf): The Stable Abstractions Principle. Abstractness increases with stability.

架构原则


chanjarster
4.2k 声望244 粉丝

引用和评论

0 条评论