C ++ Critical Series 5 - Inherited Essence

zhaozj2021-02-11  169

Inheritance essence

Inheritance is a high coupling relationship with a combination and generalization (Genericity), providing an OO to one of the basic methods to combine different software components. An example of a class is also an example of all ancestors of that class. In order to ensure the effectiveness of object-oriented design, we should save the consistency of this relationship. Each redefinition in the subclass should be consistent with the initial definition in its ancestors. The needs of their ancestors should be saved in the subclass. If there is a need to be saved, it will illustrate the system's design, or inheritance in the system is inherited. Since inheritance is the basis for object-oriented design, consistent detection will be required. The implementation of non-virtual function overload in C means that the compiler will not be consistently detected. C does not provide guarantees for object-oriented design.

Inheritance is divided into "syntax" inheritance and "semantic" inheritance two parts. Saake et al. Describes the following: "Syntax inheritance is expressed as inheritance of structural or method definition, and thus links with the reuse of the code (and the code of the inheritance method). Semantic inheritance is expressed as a target semantic (ie object Inheritance of ourselves. This inheritance form can be known from the semantic data model where it is used to represent an object that appears in several characters in an application. "[Sje 91]. Saake et al. Focused on the semantic form of inheritance. The role of the object in the system is expressed by the judgment of behavior or semantic inheritance. However, Wegner believes that the code inheritance has more practical value. He expressed the difference between syntax and semantic inheritance as a code and behavior [WEG 91] (P43). He believes that such a division will not cause one part to compatibility with the other, and often inconsisten to the other. Wegner also proposes such a question: "How should I suppress the modification of the inheritance attribute?" The code inherits provides a foundation for modularization. Behavioral inheritance depends on "IS-A" relationship. These two inheritance methods are very useful in situations. They all require testing of consistency, which is inadvertent with the actual meaningful inheritance.

It seems that in the semantic maintenance relationship, inherits the strongest form; subclasses should save all assumptions in the ancestral class.

Meyer [Meyer 96A and 96b] also classified inheritance technology. In his classification, he pointed out the 12 kinds of use of inheritance. These analysis also give us how to use inheritance for a good judgment standard, such as: When should I use inheritance, when should not be it.

Software components are like a jigsaw plate. When we assemble the juvenile panels, the shape of each board must be appropriate, but more importantly, the ultimately spelled image must be meaningful and can be said. It is more difficult to combine software components. Juvenous plates just need to be recombined with a complete image. What kind of results will be obtained for the combination of software components, which we cannot foresee. Worse, each piece of the jigsaw puzzle is usually generated by different programmers, so that the entire system is combined, the requirement of their anastomosis is higher.

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

New Post(0)