Poolable abstract class
Objects of this class can be pooled in the ObjectPool for later reuse.
Should be added as a mixin.
abstract class Poolable {
/**
* Creates a new [Poolable] of [Type] [type].
*
* The instance created with [createPoolable] should be created with
* a zero-argument contructor because it will only be called once. All fields
* of the created object should be set in the calling factory constructor.
*/
factory Poolable.of(Type type, CreatePoolable createPoolable) {
return ObjectPool.get(type, createPoolable);
}
/**
* If you need to do some cleanup before this object moves into the Pool of
* reusable objects.
*/
void cleanUp();
/**
* Calls the cleanup function and moves this object to the [ObjectPool].
*/
void moveToPool() {
cleanUp();
ObjectPool.add(this);
}
}
Constructors
factory Poolable.of(Type type, CreatePoolable createPoolable) #
Creates a new Poolable of [Type] [type].
The instance created with createPoolable should be created with a zero-argument contructor because it will only be called once. All fields of the created object should be set in the calling factory constructor.
factory Poolable.of(Type type, CreatePoolable createPoolable) {
return ObjectPool.get(type, createPoolable);
}
Methods
abstract void cleanUp() #
If you need to do some cleanup before this object moves into the Pool of reusable objects.
void moveToPool() #
Calls the cleanup function and moves this object to the ObjectPool.
void moveToPool() {
cleanUp();
ObjectPool.add(this);
}