Hello guys, I have a doubt about what really does one piece of code.
I have pooling implemented this way (not entirely, just the simple way): http://www.java-gaming.org/topics/object-pooling/27133/view.html
But, I made some little changes.
The “newObject” method of the factory always returns null. Why is that? Because I want to reuse an abstract class which has a lot of sub-classes which implement the abstract methods. Something like this:
abstract BaseClass ____ ConcreteClass1
|____ ConcreteClass2
|____ etc…
Every ConcreteClassN has his own vars and stuff. And I dont want to do a pool for every one of them. I want to make a pool for the abstract class and reuse that “memory space” for a ConcreteClass (any).
So…I “get” an object this way:
BaseClass base= basePool.get();
Remember, the newMethod returns always null. So, if no objects are on the stack, get() will return null (I dont mind).
But lets see when the get() returns something. That something is a ConcreteClass object (don’t know exactly which one of them) that has been recycled somewhere. It uses memory and then what I do, for example, is:
base= new ConcreteClass2(data);
Is this code reusing the memory used by the “base” object which is actually a recycled ConcreteClassN object? Im not very sure lol
(btw, this works as expected)
Thank you guys for the help!