Advertisement
durss

Singleton sample

Jun 6th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.    
  3.     import flash.errors.IllegalOperationError;
  4.    
  5.     /**
  6.      * Singleton
  7.      *
  8.      * @author Francois
  9.      * @date 6 juin 2011;
  10.      */
  11.     public class Poil{
  12.        
  13.         private static var _instance:Poil;
  14.        
  15.        
  16.        
  17.         /* *********** *
  18.          * CONSTRUCTOR *
  19.          * *********** */
  20.         /**
  21.          * Creates an instance of <code>Poil</code>.
  22.          */
  23.         public function Poil(enforcer:SingletonEnforcer) {
  24.             if(enforcer == null) {
  25.                 throw new IllegalOperationError("A singleton can't be instanciated. Use static accessor 'getInstance()'!");
  26.             }
  27.             initialize();
  28.         }
  29.  
  30.        
  31.        
  32.         /* ***************** *
  33.          * GETTERS / SETTERS *
  34.          * ***************** */
  35.         /**
  36.          * Singleton instance getter.
  37.          */
  38.         public static function getInstance():Poil{
  39.             if(_instance == null)_instance = new  Poil(new SingletonEnforcer());
  40.             return _instance;  
  41.         }
  42.  
  43.  
  44.  
  45.         /* ****** *
  46.          * PUBLIC *
  47.          * ****** */
  48.  
  49.  
  50.        
  51.        
  52.         /* ******* *
  53.          * PRIVATE *
  54.          * ******* */
  55.         /**
  56.          * Initialize the class.
  57.          */
  58.         private function initialize():void {
  59.            
  60.         }
  61.        
  62.     }
  63. }
  64.  
  65. internal class SingletonEnforcer{}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement