I'm working on a physics simulation.
I have an ArrayList
that holds all the objects in my simulation. I have a parent class: Shape
, and two child classes: Circle
and Rectangle
.
The parent class, of course, doesn't have a draw()
method but each of the child classes does. Therefore, when I'm looping trough the list to draw each element, it doesn't allow me because there isn't a draw()
method in the Shape
class (as I'm defining the list as ArrayList<Shape>
, and adding each new element with a child class instance).
Is there a way to resolve this problem in a good and neat way?