zoukankan      html  css  js  c++  java
  • AS单例模式

    AS3.0

    懒汉模式:要用的时候就去实例化它,也就是只声明不实例化:var sp:Sprite;

    饿汉模式:使用之前去实例化它,声明变量的时候实例化: var sp:Sprite=new Sprite();

    单例模式:一个类只有一个实例,并且只实例化一次

     1 package  antCodes
     2 {
     3     /**
     4      * ...
     5      * AS单例模式
     6      * @author Dong
     7      */
     8     public class Singleton 
     9     {
    10         private static var _instance:Singleton;
    11         
    12         public function Singleton() 
    13         {
    14             if (_instance != null) {
    15                 throw new Error("Abstract Method!");
    16             }
    17             _instance = this;
    18         }
    19         private static function getInstance():Singleton {
    20             if (_instance == null) {
    21                 _instance = new Singleton();
    22             }
    23             return _instance;
    24         }
    25     }
    26 }



  • 相关阅读:
    浅谈线段树
    浅谈KMP
    20200729线上模拟题解
    20200727线上模拟题解
    声明
    tarjan--割点,缩点
    20201029模拟
    高精模板
    二分图--二分图的几种模型
    树的直径与树的重心
  • 原文地址:https://www.cnblogs.com/finger/p/2438731.html
Copyright © 2011-2022 走看看