Last active
February 4, 2017 18:06
-
-
Save onionmk2/61d8420f2629121f0a9d6cf8363e2e27 to your computer and use it in GitHub Desktop.
singleton vs singleton CQS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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