private void AddAndromeda() { //Nice I can get my instance here... var univer = Univer.Instance; Univer.AddGalaxies("Andromeda"); }
//the private construtor private Univer() { //the check for unicity if (Instance == null) { Instance = new Univer(); } }
private void AddMilkyWay() { //...And here ! //It will be the same even if i'm not in the same project or solution... //Reminder do not mess the Univer in others projects, it could be painful to change... var univer = Univer.Instance; Univer.AddGalaxies("MilkyWay"); }
public void Use_Pattern_Singleton_With_Design() { //Let talk about something bigger UNIVER ! AddMilkyWay(); AddAndromeda(); var univer = Univer.Instance; Univer.ShowGalaxies(); }