-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDefaultInterfaceImplementation.cs
More file actions
98 lines (78 loc) · 2 KB
/
DefaultInterfaceImplementation.cs
File metadata and controls
98 lines (78 loc) · 2 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
void Main()
{
ICustomer guess = new Guess();
ICustomer.SetLoyaltyThresholds(TimeSpan.FromDays(10),20,0.3m);
guess.ComputeLoyaltyDiscount().Dump();
}
interface ICustomer : IOrder
{
IEnumerable<IOrder> PreviousOrders { get;}
DateTime DateJoined { get;}
DateTime? LastOrder { get;}
string Name { get;}
IDictionary<DateTime,string> Reminders { get;}
public static void SetLoyaltyThresholds(
TimeSpan ago,
int minimumOrders = 10,
decimal percentageDiscount = 0.10m)
{
length = ago;
orderCount = minimumOrders;
discountPercent = percentageDiscount;
}
private static TimeSpan length = new TimeSpan(365 * 2, 0, 0, 0); // two years
private static int orderCount = 10;
private static decimal discountPercent = 0.10m;
public decimal ComputeLoyaltyDiscount() => DefaultLoyaltyDiscount(this);
protected static decimal DefaultLoyaltyDiscount(ICustomer c)
{
DateTime start = DateTime.Now - length;
if ((c.DateJoined < start) && (c.PreviousOrders.Count() > orderCount))
{
return discountPercent;
}
return 0;
}
}
interface IOrder
{
DateTime Purchased {get;}
float Cost {get;}
}
class Guess : ICustomer
{
public IEnumerable<IOrder> PreviousOrders
{
get
{
var dummyList = new List<IOrder>();
dummyList.Add(new Cupcake());
dummyList.Add(new Beer());
return dummyList;
}
}
public DateTime DateJoined => DateTime.Now.AddYears(-4);
public DateTime? LastOrder => DateTime.UtcNow.AddDays(-6);
public string Name => "Daniel Sutto";
public IDictionary<DateTime, string> Reminders =>
new Dictionary<DateTime,string>();
public DateTime Purchased => DateTime.UtcNow;
public float Cost => 122.4f;
public decimal ComputeLoyaltyDiscount()
{
if (PreviousOrders.Any() == false)
return 0.50m;
else
return ICustomer.DefaultLoyaltyDiscount(this);
}
}
class Cupcake : IOrder
{
public DateTime Purchased => default(DateTime);
public float Cost => default(float);
}
class Beer : IOrder
{
public DateTime Purchased => default(DateTime);
public float Cost => default(float);
}