多语言展示
当前在线:1077今日阅读:27今日分享:41

面向对象设计原则

介绍面向对象设计原则
方法/步骤
1

单一职责原则    定义:一个对象应该只包含单一定职责,并且该职责被完整地封装在一个类中。    definition: Every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class.

2

开闭原则    定义:一个软件实体应当对扩展开放,对修改关闭,也就是说在设计一个模块的时候,应当使这个模块可以在不被修改的前提下被扩展,即实现在不修改源代码的情况下改变这个模块的行为。    definition: Software entities should be open for extension,but closed for modification.

3

里氏代换原则    定义:所有引用基类的地方必须透明地使用其子类地对象。    definition: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.

4

依赖倒转原则    定义: 要针对接口编程,不要针对实现编程。    definition: Program to an interface,not an implementation.

5

接口隔离原则    定义:客户端不应该依赖那些它不需要地接口。    definition: Clients should not be forced to depend upon interfaces that they do not use.

6

合成复用原则    定义:尽量使用对象组合,而不是继承来达到复用的目的。    definition: Favor composition of objects over inheritance as reuse mechanism.

7

迪米特法则    定义:每一个软件单位对其他的单位都只有最少的知识,而且局限于那些与本单位密切相关的软件单位。    definition: Each unit should have only limited konwledge about other units: only uints 'closely' related to the current unit.

推荐信息