Object-oriented design principles (sorting in agile development)

xiaoxiao2021-03-06  70

"Open-Closed" principle (OCP) to variability package

The OpenThe Open - Closed Principleclosed PrinciPle

Any system will change in its life cycle. If we want to develop the system will not be abandoned after the first version, then we must firmly remember this.

Software makes up entities (classes, modules, functions, etc.) should be scalable, but cannot be modified.

OCP OCP characteristics

Scalable (open to extensions)

The behavior function of the module can be expanded, when the application requirements change or need to meet new application requirements, we can make the module work in different ways.

Not changed (closed by changing)

The source code of these modules is unmodolate. Anyone does not modify the source code of the module.

The key is abstraction!

The module can operate an abstract body. Since the module depends on a fixed abstraction, it can be unmissible; at the same time, the behavior function of this module can be extended by derived from this abstract body.

Programs that meet the OCP principles are only changed by increasing the code rather than changing the existing code, so such a program does not cause a change in chain reactions like non-open-closed-closed programs.

Variable package

Consider what possible changes in the system

A variability should not be scattered in many corners of the code, but should be encapsulated into an object.

Correct understanding inheritance

One variability should not be mixed with another variability

SERATEGIC Closure does not have a large program to be 100% enclosed. Generally speaking, no matter how "closed" is the module, there will be some changes that cannot be closed. Since it is impossible to completely enclose, this problem must be selected. That is, the designer must make a choice for the module designed for him (her).

How to inherit the Rid Replacement Principle (LSP)

LiskoV replacement principle

LSP

LSP The Liskov Substitution PrinciPle

The main mechanism behind the principle of OCP is abstract and polymorphism. The key mechanism to support abstract and polymorphism is inheritance.

Definition of the definition of the LSP LSP

If the object O1 of each type S is existed, there is a type T object O2, so that in all programp written for T, after the O1 is replaced with O2, the behavior function of the program P is unchanged, then S is a sub-t Types of.

The LSP principle clearly states that IS-A relationships in OOD are in terms of behavior. Behavior is not inherent, private, but an external, disclosed, is the customer program. Behavior is the problem that the software is concerned! All derived class behavior features must be consistent with the client program.

LSP LSP and DBC DBC

DBC (Design By Contract) Defines the relationship between classes and its customers as a formal agreement, clarifying the rights and obligations of the parties. DBC is declared as a preconction and followcondition. In order to make the way, the prerequisites must be true. After completing, the method guarantees that follow-up conditions are true. DBC's requirement requirement when redefining the routine in the derived class, we can only replace with a weaker prerequisite and stronger follow-up conditions.

LSP-conclusion

The LSP principle is an important feature of the OCP principle application. We can reuse those functions that use base classes and modify derived types when they can renew their base classes. Dependency reversal principle (DIP) programming for interface

The high-level module should not depend on the low-level module. Both should depend on abstraction.

Abstract should not depend on the details. Details should depend on abstraction.

Implementation

Separate abstraction from the specific details of the problem, and coupling the class in abstraction.

insufficient

Resulting in a large number of classes

Assume that all specific classes will change, this is not always correct

DIP and design pattern

DIP is based on LSP, which is the main means of achieving OCP. It is the main guiding principle of design model research and application.

Interface Isolation Principle (ISP) Appropriate Division Role and Interface

Interface Contamination An Unreported designer often wants to save the number of interfaces, merged some features close or functionally related interface, and seeing this as part of the code optimization.

Definition: From an angle of a customer class: A class of dependencies on another class should be based on the smallest interface. It is better to use multiple special interfaces than using a single total interface.

Synthesis / Polymerization Principle (CARP) Try to use synthetic / polymerization, try not to use inheritance

Definition: Use some existing objects in a new object, making it part of the new object; new objects reach the purpose of multiplex these objects by delegating the objects of these objects

转载请注明原文地址:https://www.9cbs.com/read-119914.html

New Post(0)