-
Notifications
You must be signed in to change notification settings - Fork 4
/
CaffeineBeverage.cs
62 lines (53 loc) · 1.43 KB
/
CaffeineBeverage.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BehavioralPatterns.TemplateMethod
{
public abstract class CaffeineBeverage
{
// Template Method
// It serves as a template for an algorithm.
// In this case, an algorithm for making caffeinated beverages.
public void PrepareRecipe()
{
BoilWater();
Brew(); // abstract -> handled by subclass
PourInCup();
AddCondiments(); // abstract --> handled by subclass
}
public abstract void Brew();
public abstract void AddCondiments();
public void BoilWater()
{
Console.WriteLine("Boiling water");
}
public void PourInCup()
{
Console.WriteLine("Pouring in a cup");
}
}
public class Tea : CaffeineBeverage
{
public override void Brew()
{
Console.WriteLine("Steeping the tea");
}
public override void AddCondiments()
{
Console.WriteLine("Adding Lemon");
}
}
public class Coffee : CaffeineBeverage
{
public override void Brew()
{
Console.WriteLine("Dripping Coffee through filter");
}
public override void AddCondiments()
{
Console.WriteLine("Adding Sugar and Milk");
}
}
}