private static void TestSingletonPattern() { ChocolateBoiler chocolateBoiler = ChocolateBoiler.Instance; Console.WriteLine(chocolateBoiler.Fill()); Console.WriteLine(chocolateBoiler.Boil()); Console.WriteLine(chocolateBoiler.Drain()); }
public static void Start() { ChocolateBoiler boiler = ChocolateBoiler.GetInstance(); boiler.Fill(); boiler.Boil(); boiler.Drain(); }
static void Main(string[] args) { ChocolateBoiler boiler = ChocolateBoiler.Instance; boiler.Fill(); boiler.Boil(); boiler.Drain(); // will return the existing instance ChocolateBoiler boiler2 = ChocolateBoiler.Instance; }
static void Main(string[] args) { ChocolateBoiler chocolateBoiler = new ChocolateBoiler(); chocolateBoiler.GetInstance(); chocolateBoiler.Fill(); chocolateBoiler.Boil(); chocolateBoiler.Drain(); Console.ReadLine(); }
/// <summary> /// O padrão Singleton garante que uma classe tenha apenas uma instância e fornece um ponto global de acesso a ela. /// </summary> private static void TestSingleton() { ChocolateBoiler boilerReference1 = ChocolateBoiler.GetInstance(); ChocolateBoiler boilerReference2 = ChocolateBoiler.GetInstance(); boilerReference1.Fill(); boilerReference2.Fill(); boilerReference1.Drain(); boilerReference2.Boil(); boilerReference1.Drain(); }
static void Main() { CheckNull(); ChocolateBoiler boiler = ChocolateBoiler.GetInstance(); CheckNull(); //should work correct boiler.Fill(); boiler.Boil(); boiler.Drain(); Console.WriteLine("\n"); //should work incorrect boiler.Boil(); boiler.Drain(); boiler.Fill(); boiler.Fill(); boiler.Drain(); Console.ReadKey(); }