forked from abishekaditya/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChocolateBoiler.cs
44 lines (35 loc) · 1.09 KB
/
ChocolateBoiler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
namespace SingletonPattern
{
internal partial class ChocolateBoiler
{
private static readonly Lazy<ChocolateBoiler> _singleton = new Lazy<ChocolateBoiler>(() => new ChocolateBoiler());
public static ChocolateBoiler GetInstance() => _singleton.Value;
private Status _boiler;
private ChocolateBoiler()
{
Console.WriteLine("Starting");
_boiler = Status.Empty;
}
public void Fill()
{
if (!IsEmpty) return;
Console.WriteLine("Filling...");
_boiler = Status.InProgress;
}
public void Drain()
{
if (!IsBoiled) return;
Console.WriteLine("Draining...");
_boiler = Status.Empty;
}
public void Boil()
{
if (IsBoiled || IsEmpty) return;
Console.WriteLine("Boiling...");
_boiler = Status.Boiled;
}
private bool IsEmpty => (_boiler == Status.Empty);
private bool IsBoiled => (_boiler == Status.Boiled);
}
}