-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
45 lines (40 loc) · 1.44 KB
/
Program.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
using System;
using System.Collections.Generic;
namespace ChainOfResponsibilityPattern
{
internal class Program
{
private static void Main()
{
var parcelList =
new List<Parcel>
{
new Parcel {IsInsured = false, Value = 2500m},
new Parcel {IsInsured = true, Value = 10m},
new Parcel {IsInsured = false, Value = 10m},
new Parcel {IsInsured = true, Value = 0m},
new Parcel {IsInsured = false, Value = 45m},
new Parcel {IsInsured = false, Value = 5m},
new Parcel {IsInsured = false, Value = 150m},
};
var budgetHandler = new ParcelHandlerBudget();
var normalHandler = new ParcelHandlerNormal();
var deluxeHandler = new ParcelHandlerDeluxe();
budgetHandler.SetNewHandler(normalHandler);
normalHandler.SetNewHandler(deluxeHandler);
foreach (Parcel parcel in parcelList)
{
try
{
string result = budgetHandler.Handle(parcel);
Console.WriteLine(result);
}
catch (Exception)
{
Console.WriteLine("Parcel rejected");
}
}
Console.ReadKey();
}
}
}