Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active February 4, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onionmk2/61d8420f2629121f0a9d6cf8363e2e27 to your computer and use it in GitHub Desktop.
Save onionmk2/61d8420f2629121f0a9d6cf8363e2e27 to your computer and use it in GitHub Desktop.
singleton vs singleton CQS
using System;
public class Singleton {
private static Singleton mInstance;
private Singleton () { // Private Constructor
}
public static Singleton Instance {
get {
if( mInstance == null ) {
mInstance = new Singleton();
}
return mInstance;
}
}
public void hi(){ Console.WriteLine("hi");}
}
public class SingletonCQS {
private static SingletonCQS mInstance;
private SingletonCQS () { // Private Constructor
}
public static void Create() {
if(mInstance == null) {
mInstance = new SingletonCQS();
}
}
public static SingletonCQS GetInstance() {
return mInstance;
}
public void hi(){ Console.WriteLine("hi");}
}
class MainClass {
public static void Main (string[] args) {
Singleton.Instance.hi();
SingletonCQS.Create();
SingletonCQS.GetInstance().hi();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment