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

xiaoxiao2024-12-21  11

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(){} }

 

转载请注明原文地址: https://www.6miu.com/read-5021621.html

最新回复(0)