A simple single-State mode class of ActionScript -------- ActionScript 3.0 Cookbook (II)
Just now, when I saw section 3.0 in the event of creating static methods and attributes in the event of event 2.4 cookbook, I saw that the most important application of static in Private Static is in single-State mode. It reminds me that I used to read the design pattern book and wrote a very simple single-State pattern class by the way.
package SRC <br/> {</P> <p>/** <br/> * written by leezhm, 10th February, 2009 <br/> * contact: leezhm@126.com <br/> * an example of Singleton class <br/> **/</P> <p> public class csingleton <br/> {<br //> // variable <Br/> Private Static Var _ instance = new csingleton (); </P> <p> protected function csingleton () <br/>{< br/>}</P> <p> Public static function getinstance (): csingleton <br/>{< br/> If (undefined! = Csingleton. _ instance) <br/>{< br/> return csingleton. _ instance; <br/>}< br/> else <br/>{< br/> throw error ("cocould not create the instace! "); <Br/>}</P> <p >}
(BTW: csdnCodeI have been looking forward to the display method for a long time. I just found it and am excited)
The single-State mode is mainly used in a design mode where only one instance can be created for a class.