first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Gang of Four Patterns: Flippant Remarks about Singleton and Monostate

Singleton:

public class Singleton
{
    private static Singleton theInstance = null;
    private Singleton() {}

    public static Singleton Instance()
    {
        if (theInstance == null) theInstance = new Singleton();
        return theInstance;
    }
}

Monostate:

public class Monostate
{
    private static int itsX = 0;
    public Monostate() {}

    public void setX(int x) { itsX = x; }
    public int getX() { return itsX; }
}
mod date: 2007-10-19T04:03:25.000Z