`
jiadong
  • 浏览: 29053 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

设计模式的六大原则

阅读更多

--【读书笔记】

 

1. 单一职责(Single Responsibility Principle)
There should never be more than one reason for a class to chenge.
单一职责原则提出了一个编写程序的标准,用“职责”或“变化原因”来衡量接口或者类设计得是否优良,但是职责和变化原因都是不可度量的,因项目而异,因环境而异。
2. 里氏替换原则(Liskov Subsitution Principle)
A If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T,the behavior of P is unchanged
when o1 is substitued for o2 then S is a subtype of T.
B Functions that use pointers or references to base classes must be able to user objects of derived classes without knowing it .
3. 依赖倒置原则
依赖体现在抽象层,不体现在具体的实现层。
4. 接口隔离原则
定义最小的接口,使得接口更加的灵活,客户端不依赖于不需要的接口。
clinets should not be forced to  depend upon  interfaces that they  don't use.
clients dependcy of one class to another one should depend on the smallest possible interface.
5. 迪米特法则(Law of Demeter),最少知识原则(Least Knowledge Principle)
一个对象应该与其他对象有最少的了解。
6. 开闭原则
Software entities like classes,modules and functions should be open for extension but close for modifications.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics