
net.sf.javagimmicks.lang.CreateOnDemandObjectContainer Maven / Gradle / Ivy
package net.sf.javagimmicks.lang;
/**
* An implementation of {@link ObjectContainer} that creates the instance using
* when it is requested for the first time using an underlying {@link Factory}
* which is commonly known as "lazy loading" pattern.
*
* @param
* the type of object the container can carries
*/
public class CreateOnDemandObjectContainer extends AbstractCreateOnDemandObjectContainer
{
private E _instance;
/**
* Creates a new instance for the given {@link Factory}
*
* @param factory
* the {@link Factory} to use for creating the instance
*/
public CreateOnDemandObjectContainer(final Factory factory)
{
super(factory);
}
@Override
protected E getInstance()
{
return _instance;
}
@Override
protected void setInstance(final E instance)
{
_instance = instance;
}
}