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