Singleton Pattern

I have been looking at patterns a lot lately and have desided to write up about them and how to implement them, so I had a couple of free hours this afternoon so I wrote up the first one which is the most commonly used, the Singleton pattern. I have written up in flash paper and pdf plus added all the files to download.
Sorry about the spelling and grammar, didn’t have time to check it, but the patterns works.

Flash Paper
PDF
See how it works with the test swf
Download all the files

enjoy.

Share the love

4 thoughts on “Singleton Pattern

  1. Sascha/FGPW says:

    Nice and easy to understand tutorial the way I like it! Looking forward to see more patterns explained here! :smile:

  2. tripleaxis says:

    Small point, but it’s a bit neater if you make the getInstance method a getter.

    so you end up with Singleton.instance.getAmount();

    Also, you can create a static Main() method to instantiate your class – it’s not like you’re going to use it ever again…
    public static Main():Singleton{
    Singleton._instance = new Singleton();
    }

    this hooks up nicely with MTASC..

  3. Simon Wacker says:

    Hi Darren,

    very good articles!
    But, I nevertheless wanna add that the use of the singleton pattern is controversial. I have written an article about why not to singleton or moreover how to singleton in a different fassion that is not as intrusive as the default implementation in the GoF book etc.
    You may take a look at it at: http://www.simonwacker.com/blog/archives/000079.php
    I am currently working on a context implementation that does some of the concepts I mention in the article in a better way and is based on the context and bean factory support of the springframework (http://www.springframework.org). It will be in the next as2lib release.

    Greetings,
    Simon

  4. [...] James Hay and I am an idiot. A friend of mine (Darren Richardson) had recently written an article on the Singleton pattern. I’d been meaning to read it for weeks but finally had the chance to sit d [...]