public static Paramatma GetInstance() { lock (Padlock) { if (Instance == null) { Instance = new Paramatma(); } return(Instance); } }
public static void ExecuteTest() { Paramatma LordParamatma = Paramatma.GetInstance(); Person KrsnaDas = new Person("Krsna Das"); Person RamaDas = new Person("Rama Das"); /* * Krsna Das will perform some action and paramatma * will show it memorized the action, just as how we coded it. */ KrsnaDas.PerformAction("chants some rounds"); LordParamatma.DisplayMemory(); /* * Rama Das will now perform some action and Paramatma will * show both the memorized action of Krsna Das and Rama Das. * * This shows that Krsna Das and Rama Das are referencing * the same instance of Lord Paramatma. */ RamaDas.PerformAction("cooks prasada"); LordParamatma.DisplayMemory(); /* * This example shows that a difference instance of Paramatma * does not share the same reference. * * It will display the text: "Nothing has been memorized!" * * A workaround would be to make the MemoryArray a static * field and instantiate the list at the class level (not * the constructor). */ Paramatma anotherParamatma = new Paramatma(); anotherParamatma.DisplayMemory(); }
public Person(string name) { Paramatma = Paramatma.GetInstance(); PersonName = name; }