A
A
Antonio2020-02-25 12:37:30
Java
Antonio, 2020-02-25 12:37:30

How in Java to break a class into three smaller ones so that the inheritance chain is not lost?

There is a class B. It is necessary to split it into classes H and G, without losing the inheritance chain, so that the methods of the new classes are also available to the heirs of class B, and the methods of class A and B are available to classes H and G.
5e54eac8247b0631813927.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasily Bannikov, 2020-03-19
@Apokaliepsis

- Drag and drop the logic you need into the H and G class (without inheritance)
- In the 'B' class, make fields for the H and G instances (think through the constructor, or initialize there.
- 'B' inherit from A. Optional somehow give descendants access to H and G (via B methods or directly to fields)

V
Vladimir Korotenko, 2020-02-25
@firedragon

Java does not support multiple inheritance, but you can take out common interfaces and inherit from them.
What kind of account?
https://javarush.ru/groups/posts/731-mnozhestvenno...

S
Sergey Shvyrev, 2020-02-26
@CellycoMobiles

Java does not support multiple inheritance.
Adult developers use the Composition pattern.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question