六大OO设计原则

套用各种DP写一个系统,跑起来了,但后来发现真有变化来临的时候想扩展还得大规模改动甚至重写,这就是传说中的DP乱套了,达不到效果反而徒增工作量,内心惭愧,于是细读OO大师的设计信条,才慢慢明晓DP要怎么样实作才能真正达到效果,记下六大原则原文,肃清乱套之风,以作警戒。

Single Responsibility Principle: There should never be more than one reason for a class to change.

Open Closed Principle: Software entities like classes, modules and functions should be open for extension but closed for modifications.

Liskov Substitution Principle: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.

Law of Demeter: Least Knowledge Principle. Only talk to your immedate friends.

Interface Segregation Principle: Clients should not be forced to depend upon interfaces that they don't use. The dependency of one class to another one should depend on the smallest possible interface.

Dependence Inversion Principle: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值