public static void Start() { ChocolateBoiler boiler = ChocolateBoiler.GetInstance(); boiler.Fill(); boiler.Boil(); boiler.Drain(); }
public void TestInstanceCount() { ChocolateBoiler.GetInstance(); ChocolateBoiler.GetInstance(); var instance = ChocolateBoiler.GetInstance(); Assert.AreEqual(1, ChocolateBoiler.count); instance.Fill(); }
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(); }