问题描述
最近我听说OOP(Java)有9条规则.我只知道四个作为抽象,多态,继承和封装.面向对象操作还有其他规则吗?
Recently I heard that there are 9 rules for OOP(Java). I know only four as Abstraction, Polymorphism, Inheritance and Encapsulation. Are there any more rules for OOP?
推荐答案
似乎您正在寻找的是面向对象设计原理.
Seems like what you're looking for are the Principles of Object-Oriented Design.
摘自敏捷软件开发原则,模式和实践.这些原则是数十年来软件工程经验的来之不易的产品.它们不是一心一意的产品,但是它们代表了众多软件开发人员和研究人员的集成和著作.尽管此处将它们作为面向对象设计的原理进行了介绍,但它们实际上是长期存在的软件工程原理的特例.
Summarized from Agile Software Development Principles, Patterns, and Practices. These principles are the hard-won product of decades of experience in software engineering. They are not the product of a single mind, but they represent the integration and writings of a large number of software developers and researchers. Although they are presented here as principles of object-oriented design, they are really special cases of long-standing principles of software engineering.
SRP单一职责原则:班级应该只有一个改变的理由.
SRP The Single Responsibility Principle A class should have only one reason to change.
OCP开放式原则应该对软件实体(类,程序包,方法等)开放以进行扩展,而封闭以进行修改.
OCP The Open-Closed Principle Software entities (classes, packages, methods, etc.) should be open for extension, but closed for modification.
LSP Liskov替换原理子类型必须可以替换其基本类型.
LSP The Liskov Substition Principle Subtypes must be substitutable for their base types.
DIP依赖倒置原则抽象不应依赖细节.详细信息应取决于抽象.
DIP The Dependency Inversion Principle Abstractions should not depend upon details. Details should depend upons abstractions.
ISP接口隔离原则不会迫使客户依赖于他们不使用的方法.接口属于客户端,而不属于层次结构.
ISP The Interface Segregation PrincipleClients shold not be forced to depend upon methods that they do not use. Interfaces belong to clients, not to hierarchies.
REP释放-重用等效原则再利用的颗粒就是释放的颗粒.
REP The Release-Reuse Equivalency PrincipleThe granule of reuse is the granule of release.
CCP通用闭包原则包中的类应针对相同的更改一起关闭.影响封闭程序包的更改会影响该程序包中的所有类,而不会影响其他程序包.
CCP The Common Closure PrincipleThe classes in a package should be closed together against the same kinds of changes. A change that affects a closed package affects all the classes in that package and no other packages.
CRP通用重用原则包中的类可以一起重用.如果您重用包中的一个类,则全部重用它们.
CRP The Common Reuse PrincipleThe classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.
ADP词性依赖原则依赖性图中不允许有循环.
ADP The Acylcic Dependencies PrincipleAllow no cycles in the dependency graph.
SDP稳定依赖原则取决于稳定性的方向.
SDP The Stable Dependencies PrincipleDepend in the direction of stability.
SAP稳定抽象原则程序包应尽可能稳定抽象.
SAP The Stable Abstractions PrincipleA package should be as abstract as it is stable.
这篇关于OOP有任何规则吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!