-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryMethod.cs
More file actions
110 lines (92 loc) · 3.71 KB
/
Copy pathFactoryMethod.cs
File metadata and controls
110 lines (92 loc) · 3.71 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
namespace Lab2.Patterns.FactoryMethod;
public enum SubscriptionType
{
Domestic,
Educational,
Premium
}
public abstract class Subscription
{
protected Subscription(decimal monthlyFee, int minimumPeriodMonths, IReadOnlyList<string> channels, IReadOnlyList<string> features)
{
MonthlyFee = monthlyFee;
MinimumPeriodMonths = minimumPeriodMonths;
Channels = channels;
Features = features;
}
public decimal MonthlyFee { get; }
public int MinimumPeriodMonths { get; }
public IReadOnlyList<string> Channels { get; }
public IReadOnlyList<string> Features { get; }
public abstract string Name { get; }
public override string ToString() =>
$"{Name}: {MonthlyFee:C}/міс, мін. {MinimumPeriodMonths} міс., " +
$"канали [{string.Join(", ", Channels)}], можливості [{string.Join(", ", Features)}]";
}
public sealed class DomesticSubscription() : Subscription(
199m,
3,
["News UA", "Family TV", "Cinema Home"],
["HD-якість", "2 пристрої"])
{
public override string Name => nameof(DomesticSubscription);
}
public sealed class EducationalSubscription() : Subscription(
149m,
6,
["Discovery Learn", "History Lab", "Science Kids"],
["Лекції", "Архів записів", "Батьківський контроль"])
{
public override string Name => nameof(EducationalSubscription);
}
public sealed class PremiumSubscription() : Subscription(
349m,
1,
["All Sports", "Cinema Max", "World Series", "Music 4K"],
["4K-якість", "5 пристроїв", "Преміум підтримка", "Офлайн перегляд"])
{
public override string Name => nameof(PremiumSubscription);
}
public abstract class SubscriptionCreator
{
public abstract string ChannelName { get; }
public Subscription CreateSubscription(SubscriptionType type)
{
Subscription subscription = type switch
{
SubscriptionType.Domestic => CreateDomesticSubscription(),
SubscriptionType.Educational => CreateEducationalSubscription(),
SubscriptionType.Premium => CreatePremiumSubscription(),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
ApplyPurchaseBonus(subscription);
return subscription;
}
protected abstract DomesticSubscription CreateDomesticSubscription();
protected abstract EducationalSubscription CreateEducationalSubscription();
protected abstract PremiumSubscription CreatePremiumSubscription();
protected virtual void ApplyPurchaseBonus(Subscription subscription)
{
}
}
public sealed class WebSite : SubscriptionCreator
{
public override string ChannelName => "WebSite";
protected override DomesticSubscription CreateDomesticSubscription() => new();
protected override EducationalSubscription CreateEducationalSubscription() => new();
protected override PremiumSubscription CreatePremiumSubscription() => new();
}
public sealed class MobileApp : SubscriptionCreator
{
public override string ChannelName => "MobileApp";
protected override DomesticSubscription CreateDomesticSubscription() => new();
protected override EducationalSubscription CreateEducationalSubscription() => new();
protected override PremiumSubscription CreatePremiumSubscription() => new();
}
public sealed class ManagerCall : SubscriptionCreator
{
public override string ChannelName => "ManagerCall";
protected override DomesticSubscription CreateDomesticSubscription() => new();
protected override EducationalSubscription CreateEducationalSubscription() => new();
protected override PremiumSubscription CreatePremiumSubscription() => new();
}