------Singleton mode of design pattern

Source: Internet
Author: User

From now on, let's start with the design pattern:

<?php/*** only one instance in memory, save memory space, * Avoid frequent creation of destroyed objects, can improve performance, * Avoid multiple occupancy of shared resources * can be accessed globally * the creation of objects is too much time consuming, the cost of the source too **//**private, So they are not inherited, but many other singleton patterns can be inherited, such as a registered singleton **//**** a Hungry man single case * * When the Singleton class is loaded, instantiate an object to its own reference **/public class  Singleton{     private static singleton singleton = new  singleton ();      private singleton ();      public  static singleton getinstance () {           return singleton;     }}/**** Lazy single case, the object can be instantiated when the instance method is obtained **/public class  singleton{     private static singleton singleton;      private singleton () {}     public static synchronized  Singleton getinstance () {          if (singleton ==  null) {               singleton = new singleton ();           }           return singleton;     }}


This article is from the "Wang Nimei Adult Road" blog, reprint please contact the author!

------Singleton mode of design pattern

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.