Regardless of a language or model, the idea is the same. what is different is the details of the language.
Java version:
public class Singleton {private volatile static Singleton instance;private Singleton(){};public static Singleton getInstance(){if(instance == null){synchronized (Singleton.class) {if(instance == null){instance = new Singleton();}}}return instance;}}
C:
Public class Singleton {protected Singleton () {} Private Static volatile Singleton instance = NULL; // process of creating a unique instance in lazy mode public static Singleton instance () {If (instance = NULL) // The outer if lock (typeof (Singleton) // synchronize shared resources in multiple threads if (instance = NULL) // inner layer if instance = new Singleton (); Return instance ;}}
JS version:
VaR singletontest = (function () {function single (ARGs) {var ARGs = ARGs | []; this. name = 'singletontest'; this. X = args. X | 6; this. y = args. Y | 7 ;}; var instance; VaR _ static = {Name: 'singletontest', getinstance: function (ARGs) {If (instance === undefined) {instance = new single (ARGs) ;}return instance ;}; return-static ;}) (); // call var singletontest = singletontester. getinstance ({pointx: 5 });