I have such a structure
abstract Class Entity {
Here is the parent .. Now I have 3 children ..
Class A extends Entity{} Class B extends Entity{} Class C extends Entity{}
Each class has different things that render. One example, for example, drawing a yellow circle, the second is green text, and the third is an image.
But ... there is a thing.
Class A have List<B>... Class B have List<C>...
One entity has, for example, 10 Bs ... and each B has 20 Cs ... So, now ... I have a rendering method that displays 60x per second .. And I have to call each render method from each object.
So I have something like this
for(A a : listOfAs){ for(B b : listOfBs){ for(C c : listOfCs){ c.render(g); }b.render(g); }a.render(g); }
Now, if you assume that I have many more such objects, and I call this method 60x per second ... I find it really ... really bad practice. I don’t know how to solve this better ... I don’t think that for each cycle this is actually the best solution or not. Any ideas?
I was thinking about how to realize such a child:
Entity x = new A(); ... Entity y = new B(); ...
and therefore, but some of the classes have other methods that should be looped in this way, and I cannot name them from the parent.
For the rendering method ... Just stick to the fact that you need to loop a lot of things in a short amount of time for a long time.
I can’t get through this ... I’ve been stuck here for a long time and I’m not sure how to solve it.