在设计面向对象的程序的时,模式不是一定要套的,但是有一些原则最好是遵守这些原则已知的有七个,包括:开闭原则、里氏代换原则、依赖倒转原则、合成/聚合复用原则、迪米特法则、接口隔离原则,单一职责原则,今天小编就来说说关于面向对象的设计方法的特点?下面更多详细答案一起来看看吧!

面向对象的设计方法的特点(面向对象设计的设计原则)

面向对象的设计方法的特点

在设计面向对象的程序的时,模式不是一定要套的,但是有一些原则最好是遵守。这些原则已知的有七个,包括:开闭原则、里氏代换原则、依赖倒转原则、合成/聚合复用原则、迪米特法则、接口隔离原则,单一职责原则。

  原则简介

其中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.

,