Posted By

jasonm23 on 11/24/09


Tagged

flash Singleton Flex as3 DesignPatterns


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mattlohmann
tspitzr
mitien
elvman


AS3 Enforced Singleton


 / Published in: ActionScript 3
 

This implementation of the singleton pattern provides a way to enforce singleton usage. There are numerous Singleton implementations for AS3 (due to the lack of private constructor) this method, is the cleanest I've seen so far.

  1. package mypackage
  2. {
  3. public class SingletonExample
  4. {
  5. public function SingletonExample(enforcer:SingletonEnforcer)
  6. {
  7. }
  8.  
  9. private static var _instance : SingletonExample;
  10.  
  11. public static function getInstance():SingletonExample
  12. {
  13. if (_instance == null)
  14. _instance = new SingletonExample(new SingletonEnforcer());
  15.  
  16. return _instance;
  17. }
  18. }
  19. }
  20. class SingletonEnforcer {}

Report this snippet  

You need to login to post a comment.