C ++ criticism series - multiple inheritance

xiaoxiao2021-03-06  24

Multi-inheritance of Ian Joynercber Translation Eiffel and C provide a multi-inheritance mechanism. But Java is not because it believes that more inherits can lead to many problems. However, Java provides an interface (Interface) as an alternative mechanism, which is similar to the protocol in Objective C (Protocol). Sun claims that interfaces can provide all of the features that can be provided. This view is that this view is that this view is that this view is, especially in C to achieve multi-inheritance methods. Those who look like many inherits will be more simple reason, which has been proven to be meaningless. For example, how to develop strategies between data items with the same name from the two classes? Is it compatible between them? If so, should they be merged into an entity? How do you distinguish it if it is not compatible? ?? This list can be listed very long. Java's interface mechanism can also be used to achieve more inheritance, but it also has a very important difference (compared to C ): The interface in the inheritance must be abstract. Because there is no such thing as an interface, this eliminates the possibility of choosing from different practices. Java allows a constant field to be declared in the interface. When you need more inheritance, they merge into an entity, which will not result in ambiguity generation. However, when these constants have different values, what happens? Since Java does not support multi-inheritance, we cannot use mixing (Mixin) as in C and Eiffel. Mixing is a characteristic that it can put different non-abstract functions obtained from different classes together to form a new complex class. For example, we may want to import some UTILITY functions from different source code. However, we can also achieve the same effect by using a combination rather than inheritance, so this will not form an important attack on Java. Eiffel does not import a separate interface mechanism when solving multi-inheritance issues. Some people may think that relatively inheritance is more elegant. This is a very special point of view. Beta [Madsen 93] belongs to the kind of "more inherited is not elegant": "There is no more inheritance in beta, mainly because (for more inheritance) lacks a deep theoretical understanding, and current (for more Inherited) It is recommended that it seems very complicated. " They reference Flavors (a language that can be mixed together) as evidence. Compared with Madsen, the multi-inheritance in Flavors is related to its order, that is, inherits from (A, B) and inheritance from (B, A). The ADA95 is another language that does not support more inheritance. The ADA95 supports single inheritance and calls it tagged type extension. Others believe that for problems under certain special models, multi-inheritance can provide an elegant solution, so efforts to pay for it are also worthwhile. Although the list of many inheritances listed above is not perfect, it still shows that issues related to multi-inheritance can be identified by systematically identify, and once the problem is confirmed, they can be elegantly solved. When [Sakkinen 92] reached a deep degree for multiple inheritance studies, it has been defined above. The method used in Eiffel is that more inherits will trigger some interesting and challenging issues, then solve them again. All decisions needed by programmers are limited in the inheritance clause of the class.

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

New Post(0)