View on GitHub

Bearded-android-docs

IntroduceStaticSetter

Download this project as a .zip file Download this project as a tar.gz file

Created Sunday 27 April 2014

class Singleton
{
    static private Singleton instance = null;

    static public void setTestingInstance(Singleton newInstance)
    {
instance = newInstance
}

static public Singleton getInstance()
{
return instance == null ? new Singleton() : instance;
}

static public void resetForTesting()
{
instance = null;
}
}

Unfortunately, this approach has several downsides when you don't use Spring or another IoC framework:


Alternatives


Backlinks:

OOP:RefactoringLegacyCode
comments powered by Disqus