面向对象的设计方法的特点(面向对象设计的设计原则)
在设计面向对象的程序的时,模式不是一定要套的,但是有一些原则最好是遵守这些原则已知的有七个,包括:开闭原则、里氏代换原则、依赖倒转原则、合成/聚合复用原则、迪米特法则、接口隔离原则,单一职责原则,今天小编就来说说关于面向对象的设计方法的特点?下面更多详细答案一起来看看吧!
面向对象的设计方法的特点
在设计面向对象的程序的时,模式不是一定要套的,但是有一些原则最好是遵守。这些原则已知的有七个,包括:开闭原则、里氏代换原则、依赖倒转原则、合成/聚合复用原则、迪米特法则、接口隔离原则,单一职责原则。
原则简介
其中Robert C. Martin引入了SOLID的说法,包括了其中的五个原则。另外两个,这里把他们算成额外的两个规则。具体如下。
S . Single Responsibility Principle - SRP
An object should have only a single responsibility.
O . Open-Closed Principle - OCP
Software entities should be opened for extension, but closed for modification.
L . Liskvo Substitution Principle - LSP
If S is a subtype of T, the objects of T in a program may be replaced by objects of Type S.
I . Interface Segregation Principle - ISP
many client specific interfaces are better than one general purpose interface.
D . Dependency Inversion Principle - DIP
Depend upon abstractions. Do not depend upon concretions.
Program to an interface, not an implementation.
Ex1 . Law of Demeter - LoD
-- Principle of Least Knowledge
A given object should assume as little as possible about the structure or properties of anything else.
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com