the need for multiple inheritance

Asked 2 years ago, Updated 2 years ago, 113 views

Hi, everyone. I'm writing to learn more about multiple inheritance. Is it necessary to use multiple inheritance, or is it okay to use it in combination with generics if necessary? It's this Can anyone explain the advantages and disadvantages of using them logically compared to real-life items such as codes?

Thank you.

inheritance

2022-09-22 13:29

1 Answers

In a broad sense, all object-oriented languages support multiple inheritance. In fact, it is extremely rare to complete a design without multiple inheritance. However, there is multiple inheritance only if you avoid it.

Multiple inheritance is not bad. However, if you can accurately diagnose problems that can occur in multiple inheritance, and if you do not have the means to avoid them, you can cause mistakes. It is important to be careful because this mistake can lead to a situation where you need to redesign, like the diamond problem above.

In fact, Java has some linguistic constraints on object-oriented design to prevent contradictions of expression, such as diamond problems.

If generic is included in Java, it is not fully open to multiple inheritance. It is recommended that you have a clear understanding of the usage rules.

As an example, the function signature does not separate by Generic field name. If T,E and Zenyric variables, add(Titem) and add(Eitem) are the same function signatures and cannot have them at the same time.

It's a good attitude to understand the pros and cons of the technology that language provides. But there are reasons why language provides such a function. It is important to understand this and use it in the right place.


2022-09-22 13:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.