forked from exceptionnotfound/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeats.cs
More file actions
135 lines (120 loc) · 3.77 KB
/
Copy pathMeats.cs
File metadata and controls
135 lines (120 loc) · 3.77 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Adapter
{
public enum TemperatureType
{
Fahrenheit,
Celsius
}
/// <summary>
/// The legacy API which must be converted to the new structure (aka the Adaptee participant)
/// </summary>
class MeatDatabase
{
// Temps from http://www.foodsafety.gov/keep/charts/mintemp.html
public float GetSafeCookTemp(string meat, TemperatureType tempType)
{
if (tempType == TemperatureType.Fahrenheit)
{
switch (meat)
{
case "beef":
case "pork":
return 145f;
case "chicken":
case "turkey":
return 165f;
default:
return 165f;
}
}
else
{
switch (meat)
{
case "beef":
case "veal":
case "pork":
return 63f;
case "chicken":
case "turkey":
return 74f;
default:
return 74f;
}
}
}
public int GetCaloriesPerOunce(string meat)
{
switch (meat.ToLower())
{
case "beef": return 71;
case "pork": return 69;
case "chicken": return 66;
case "turkey": return 38;
default: return 0;
}
}
public double GetProteinPerOunce(string meat)
{
switch (meat.ToLower())
{
case "beef": return 7.33f;
case "pork": return 7.67f;
case "chicken": return 8.57f;
case "turkey": return 8.5f;
default: return 0d;
}
}
}
/// <summary>
/// The Target participant, which represents details about a particular kind of meat.
/// </summary>
class Meat
{
protected string MeatName;
protected float SafeCookTempFahrenheit;
protected float SafeCookTempCelsius;
protected double CaloriesPerOunce;
protected double ProteinPerOunce;
// Constructor
public Meat(string meat)
{
this.MeatName = meat;
}
public virtual void LoadData()
{
Console.WriteLine("\nMeat: {0} ------ ", MeatName);
}
}
/// <summary>
/// The Adapter class, which wraps the Meat class and initializes that class's values.
/// </summary>
class MeatDetails : Meat
{
private MeatDatabase _meatDatabase;
// Constructor
public MeatDetails(string name)
: base(name)
{
}
public override void LoadData()
{
// The Adaptee
_meatDatabase = new MeatDatabase();
SafeCookTempFahrenheit = _meatDatabase.GetSafeCookTemp(MeatName, TemperatureType.Fahrenheit);
SafeCookTempCelsius = _meatDatabase.GetSafeCookTemp(MeatName, TemperatureType.Celsius);
CaloriesPerOunce = _meatDatabase.GetCaloriesPerOunce(MeatName);
ProteinPerOunce = _meatDatabase.GetProteinPerOunce(MeatName);
base.LoadData();
Console.WriteLine(" Safe Cook Temp (F): {0}", SafeCookTempFahrenheit);
Console.WriteLine(" Safe Cook Temp (C): {0}", SafeCookTempCelsius);
Console.WriteLine(" Calories per Ounce: {0}", CaloriesPerOunce);
Console.WriteLine(" Protein per Ounce: {0}", ProteinPerOunce);
}
}
}