Singleton Decorator

A DecoratorPattern on SingletonDecorator.

public class SingletonDecorator implements Singleton {

private Singleton singleton;
private static String DEFAULT = "ConcreteSingleton1";

private static String getDefault() { return DEFAULT; }

public SingletonDecorator() { this(getDefault()); }

public SingletonDecorator(final String which) { this(SingletonRegistry.getSingleton(which)); }

public SingletonDecorator(final Singleton singleton) { this.singleton = singleton; }

public Singleton getInstance() { return singleton; }

// decorator interfaced methods.
}

SingletonRegistry is just a facade for Singleton creation.


EditText of this page (last edited April 30, 2012) or FindPage with title or text search