面向对象(OOD)的设计原则(一):概述

OOD设计原则概述:

 RobertCecilMartin, BertrandMeyer, BarbaraLiskov等提出了面向对象的11个设计原则,被面向对象设计师们视为OOD的圣经.可以从下面看到他们的原文:

http://c2.com/cgi/wiki?PrinciplesOfObjectOrientedDesign

http://www.objectmentor.com/

类设计原则(Class Design Principles):

  1. 单一职责原则(SRP) : 一个类应该有且只有一个改变的理由。                                                 (SRP) The Single Responsibility Principle: A class should have only one reason to change.                                                                                                                                       
  2. 开放封闭原则(OCP) :软件实体(类,模块,函数等)应该是可以扩展的,但是不能修改。     (OCP) The Open-Closed Principle: Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.                                                                  
  3. Liskov替换原则(LSP):子类必须适用于基类,即子类一定能替换基类,反之则不然. (LSP) The Liskov Substitution Principle:Subtypes must be substitutable for their base types.                                                                                                                                      
  4. 依赖倒置原则(DIP):抽象不应该依赖于细节,而细节应该依赖于抽象。                                  (DIP) The Dependency Inversion Principle :Abstractions should not depend upon details. Details should depend upon abstractions.                                                                                      
  5. 接口隔离原则(ISP):客户只要关注它们所需的接口,而不应该强迫客户依赖于它们不用的方法。 (ISP) The Interface Segregation Principle:Clients should not be forced to depend upon methods that they do not use. Interfaces belong to clients, not to hierarchies.

包内聚性原则(Principles of Package Cohesion):

  1. 重用发布等价原则(REP):重用的粒度就是发布的粒度。 (REP) The Reuse/Release Equivalency Principle:The granule of reuse is the granule of release.
  2. 共同封闭原则(CCP):包中的所有类对于同一类性质的变化应该是共同封闭的。                (CCP) The Common Closure Principle:he classes in a package should be closed together against the same kinds of changes. A change that affects a closed package affects all the classes in that package and no other packages.                                                                                                                            
  3. 共同重用原则(CRP):一个包中的所有类应该是共同重用的。
    (CRP) The Common Reuse Principle:The classes in a package are reused together. If you reuse one of the classes in the package, you reuse them all.

 包耦合性原则(Principles of Package Coupling):

  1. 无环依赖原则(ADP):在包的依赖关系图中不允许存在环。 (ADP) The Acyclic Dependencies Principle:Allow no cycles in the package dependency graph.  
  2. 稳定依赖原则(SDP):朝着稳定的方向进行依赖。                                                           (SDP) The Stable Dependencies Principle:Depend in the direction of stability.                                                                                                                                       
  3. 稳定抽象原则(SAP):包的抽象程度应该和其稳定程度一致 (SAP) The Stable Abstraction Principle:A package should be as abstract as it is stable.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值