AS3强制单例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3强制单例相关的知识,希望对你有一定的参考价值。

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

以上是关于AS3强制单例的主要内容,如果未能解决你的问题,请参考以下文章