Design object-oriented accessible software principles - one of the "Java and Mode" notes

xiaoxiao2021-03-06  90

Exterior: Using the oo language is not born to be oo. Maybe we will use Java, you will use C these OO languages ​​to implement a system, but use these languages, do not mean that your system is using OO concept design, a system that uses process concept, even These languages ​​are implemented, and can only represent your SYSTEM is designed with process concept. The language is thousands of variety, continuous improvement, maybe after several years, there will be a completely new language, with the current C , Java is completely different. But the concept of OO will not die, and he may evolve into a new Level, but it is always eternal. Therefore, it is necessary to in depth understand the concept of OO, think.

Object-oriented accessible software principles These design principles are to help us build an scalable, flexible, and insertable system. When solving specific design problems, we will rely on these ideas to make, choose our design, and they are also a variety of DESIGN PATTERN. These multiplexing principles are: OCP principles, LSP principles, DIP principles, ISP principles, CARP principles, and LOD principles. The following describes:

OCP Principles: e Wen Zen: Software Entities Should Be Open for Extension, But Closed for Modification. Principles: OCP Principles are "Open-Closed Principles", a software should open the extension and turn it off for modification. Explanation: When designing a module, it should make this module can be extended below without modification. In other words, you should change this without having to modify the source code.

The behavior of the module. This principle has 2 points requirements: ×: Extended open ×: Turn off the advantage of meeting the OCP principle system: ×: Provide new behavior by extending existing software systems, allowing the software system to meet new needs ×: Existing software Modules, especially important abstract layer modules cannot be changed, which makes changes in software systems in the change have certain stability and continuity.

How to implement an OCP principle: 1, abstract is the key. Abstract the system that needs to be designed. Hereinafter, let the abstract implementation mechanisms will change. This abstraction layer must foresee all possible extensions, and any changes will not change the abstract structure. This makes the abstract layer of the system do not need to be modified, thereby meeting the second - close modifications of the OCP principles. 2. The principle of the variable package is from another perspective, the principle of the PRINCIPLE OF ENCAPSULATION VARIATION. That is, the variable factor of the system will be found, which will be encapsulated. This principle means 2 points: ×: A variable thing should not be scattered in all parts of the system, but should be packaged inside an object; ×: A variability should not be mixed with another variability.

Relationship with other design principles LSP Principles: This principle is to say any of the places where the base class, the subclass can appear. This principle is the supplement of the OCP principle. The relationship between the base class and subclasses is the specific embodiment of the abstraction, so the LSP principle is a specific step in achieving abstraction. In general, violating the principle of LSP, certain violations of the OCP principle, and it is not necessarily established.

CARP Principles: This principle is to use more synthetic / aggregation as much as possible, rather than inheritance relationships to reach multiplexed purposes. CARP principles and LSP principles complement each other. Both are specific procedures for realizing the principle of OCP. The former requires designers first considering synthetic / polymerization relationship; the latter requires that this relationship must be determined in accordance with the inheritance relationship. The CARP principle is the necessary conditions for the principle of OCP, violates this principle, and cannot make the system to implement the object of the OCP principle. DIP principle: This principle is to reluctantly depend on abstraction, do not rely on implementation. DIP principles and OCP principles are the relationship between goals and means. OCP is the target, DIP is a means. To achieve the principle of OCP, we must adhere to the principle of DIP. Violation of the principle of DIP, it is impossible to meet the requirements of the OCP principle.

LOD principles: This principle is that a software entity should work as few as possible and other entities. When a system is facing a function extension, there will be some modules, they need to modify the pressure than other modules, if these modules are relatively isolated, then they do not pass the modified pressure to other modules. The system designed according to the LOD principle, it is relatively easy to turn off the modification when the function needs to be expanded. The LOD principle is a road to the principle of OCP.

ISP Principles: This principle is to provide the client to provide a small number of individual interfaces as possible without providing large interfaces. The ISP principles and LOD principles are all communication restrictions on software entities and another software entity. The generalized LOD principle requires as possible to limit the width and depth of communication, and the ISP principle is limited to communication width.

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

New Post(0)