Reducing memory usage for an object
I am making a Path Finding program in java and I have an object called Cell. Then with a method I generate a grid which is a 2-dimension array of objects Cell.
The object cell has two variables, int xCoord and int yCoord but my main PathFind class needd the objects to have two more variables int xParent and int yParent. But not every Cell needs to have the for variables, so I want to add those variables to the Cell object once it has been created.
Any ideas?
Re: Reducing memory usage for an object
There are many ways to implement this, but given the title of the thread - are you running into memory that would necessitate the worry? That question raised, a few ways would be to extend Cell and have the variables in the child class, or if you prefer to favor composition over inheritance create a 'wrapper' class for Cell which contains the values.