I have a structure like that
abstract Class Entity {
//some variables...
//some methods ...
public abstract void render(Graphics g);
}
Thats the parent ..Now I have 3 children..
Class A extends Entity{}
Class B extends Entity{}
Class C extends Entity{}
Every class has some different stuff do render .One is for example drawing yellow circle , second green text and the third is displaying 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 render method that renders 60x per second.. And I have to call every render method from every 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 imagine I have much more objects like that and I call this method 60x per second ... I find this really ...really bad practice.. I don't know how to solve this better or so... I don't think that this for each loop is actually the best solution or not. Anyone any ideas ?
I was thinking about implementing the child like that :
Entity x = new A(); ...
Entity y = new B(); ...
and so but some of the classes have other methods that have to be looped like that and I cannot call them from parent.
For the render method ... Just stick to the fact that you have to loop something many times in a short period of time for a long time.
I cannot progress through this ... I got stuck here for a long time and I am not sure how to solve this.