[AS3设计模式][实现][单态模式-Singleton]

package
{
    import flash.errors.IllegalOperationError;
 
    public class PublicClass
    {
        private static var instance:PublicClass;
  
        public function PublicClass(pvt:PrivateClass=null)
        {
            if(pvt == null)
                throw new IllegalOperationError("本类实例应由getInstance()获得。")
        }
  
        public static function getInstance():PublicClass
        {
            if (instance==null)
                PublicClass.instance=new PublicClass(new PrivateClass());
            return PublicClass.instance;
        }
    }
}
class PrivateClass
{
     public function PrivateClass(){}
}

 

你可能感兴趣的:(设计模式,Flash)