A criticism for C ++

zhaozj2021-02-16  62

On the one hand, the inheritance mechanism is to expand, but the other hand is also limited, and the design of the parent class must be perfect, considering all subclasses possible. This is a critique of C . Consider this problem carefully, this situation only happens when classicity is interlaced, the situation is often like this: Class A {public fun1 () {}}; // father class b: public a {}; Class C: public a {}; ... // some children class framework {use_a (a *) {..};}; to this, a design is fully compliant with the need for Framework. . . Now appears in Framework2, you want to use Class A inheritance, Class X you need to use a function that is not encountered when designing Framework, that is, this feature Class A does not provide, or there is no corresponding virtual function, then The current option either Frame2Work gives up the versatility of the A series class, or gives up that function or. . . Add a new virtual function to a. . . On the one hand, the inheritance mechanism is to expand, but the other hand is also limited, and the design of the parent class must be perfect, considering all subclasses possible. This is a critique of C . Consider this problem carefully, this situation only happens when classicity is interlaced, the situation is often like this: Class A {public fun1 () {}}; // father class b: public a {}; Class C: public a {}; ... // some children class framework {use_a (a *) {..};}; to this, a design is fully compliant with the need for Framework. . . Now appears in Framework2, you want to use Class A inheritance, Class X you need to use a function that is not encountered when designing Framework, that is, this feature Class A does not provide, or there is no corresponding virtual function, then The current option either Frame2Work gives up the versatility of the A series class, or gives up that function or. . . Add a new virtual function to a. . . This is an example of "predicting future" designs that are critical. . . (I think so I think, maybe it may be, I personally see, this question is "integrating the unicolitting of non-linking to the general situation", it is a perfectionistism. . . It is also a "dynamic type discrimination problem". . . This question says it is a "hierarchical problem". If you use virtual machines, you can get it, add more hierariquen. If you are on C , we also add a level, such as writing two classes for Framework2, with subclasses to treat special X, this problem obviously can also be resolved. A little fierce, use the Visitor method to still give the class's discriminating work to Linker. It seems that every time you look at "Do you put this work". . This is an example of "predicting future" designs that are critical. . . (I think so I think, maybe it may be, I personally see, this question is "integrating the unicolitting of non-linking to the general situation", it is a perfectionistism. . . It is also a "dynamic type discrimination problem". . .

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

New Post(0)