Hi all,
I am just getting into the world of OOP and I'm not totally sure in what situations it's better to use objects and when it's simpler to just revert to arrays.
For example, I am currently re-writing a bit of scientific code written in C that simulates the evolution of the solar system. The crux of the simulation lies in the particles in the original disc of material, which has certain properties such as mass.
In the original C code this is simply implemented as different arrays for each characteristic of the particles, with each row of each array corresponding to a particular particle. This way, during the simulation, when checks have to be performed on the particle, a simple for-loop is used along the rows of the arrays.
It seems to me however, that in terms of OOP, these particles can also be represented as objects of a particle-class that contains all the characteristics of each particle. The only problem I have in implementing this is that I have to instantiate about 1000 such particles i.e., 1000 objects and I don't know if this is less efficient than just putting the characteristics in different arrays. In addition, during the simulation I would have to have a way to scan each of the 1000 objects. This is simple enough with an array and a for-loop but I don't know how this would work with a group of objects.
Anyway, basically my question is therefore whether in this situation simple arrays are a better way to go, or should I create a class for these particles? If the latter, how do I then manage the objects during the simulation?
Thanks in advance,
Regards,
Kartik