A simple single-State mode class of ActionScript

Source: Internet
Author: User
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.

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.