V
V
Vadym Kopitsya2018-03-16 15:53:21
Java
Vadym Kopitsya, 2018-03-16 15:53:21

Data output from all sheets successors?

I have a super class, it has 2 heirs, each heir has a List. I need to merge these sheets, while the number of heirs with sheets can be added as needed. And you need to display the contents of all the sheets in the heirs through the super class in one fell swoop. The output should be one sheet in which there is data from all sheets. How can this be implemented? Where can you get info?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2018-03-16
@qonand

And you need to display the contents of all sheets in the heirs through the super class in one fell swoop

This violates one of the basic principles of inheritance: heirs should know about their parents, parents should not know about their heirs. Most likely you not absolutely correctly designed system if there are tasks of this kind. It would be easier to recommend something to you if you would describe in more detail the essence of this part of the system

M
MaxLich, 2018-03-16
@MaxLich

While this comes to mind: declare a sheet in the superclass, fill it in the heirs. In some external class (which is not included in this hierarchy), create a list of superclass heirs, and then loop through all of them and add elements from their lists to the general list.
Threat The only question here is with the types of elements. If one class is used for all products (that is, they all have the same characteristics), then the list can be immediately typed with this class. Otherwise, you can make the superclass a generic, and in each heir to determine the type of product; true, then all product types must have a common child (or common interface), etc...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question