-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (68 loc) · 2.67 KB
/
Copy pathProgram.cs
File metadata and controls
77 lines (68 loc) · 2.67 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
using Lab2.Patterns.AbstractFactory;
using Lab2.Patterns.Builder;
using Lab2.Patterns.FactoryMethod;
using Lab2.Patterns.Prototype;
using Lab2.Patterns.Singleton;
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Завдання 1. Фабричний метод");
var creators = new List<SubscriptionCreator>
{
new WebSite(),
new MobileApp(),
new ManagerCall()
};
foreach (var creator in creators)
{
foreach (SubscriptionType type in Enum.GetValues<SubscriptionType>())
{
var subscription = creator.CreateSubscription(type);
Console.WriteLine($"{creator.ChannelName} -> {subscription}");
}
}
Console.WriteLine("Завдання 2. Абстрактна фабрика");
var deviceFactories = new IDeviceFactory[]
{
new IProneFactory(),
new KiaomiFactory(),
new BalaxyFactory()
};
foreach (var factory in deviceFactories)
{
var devices = new IDevice[]
{
factory.CreateLaptop(),
factory.CreateNetbook(),
factory.CreateEBook(),
factory.CreateSmartphone()
};
Console.WriteLine(factory.BrandName);
foreach (var device in devices)
{
Console.WriteLine(device.GetFullDescription());
}
}
Console.WriteLine("Завдання 3. Одинак");
var authenticatorFromMain = Authenticator.Instance;
var authenticatorFromTask = await Task.Run(() => Authenticator.Instance);
Console.WriteLine($"Main hash: {authenticatorFromMain.GetHashCode()}");
Console.WriteLine($"Task hash: {authenticatorFromTask.GetHashCode()}");
Console.WriteLine($"Один екземпляр: {ReferenceEquals(authenticatorFromMain, authenticatorFromTask)}");
Console.WriteLine(authenticatorFromMain.Authenticate("student", "kpz-2026")
? "Автентифікація успішна."
: "Автентифікація неуспішна.");
Console.WriteLine("Завдання 4. Прототип");
var familyRoot = VirusSamples.CreateFamily();
var clonedFamily = (Virus)familyRoot.Clone();
Console.WriteLine("Оригінал:");
Console.WriteLine(familyRoot.ToTreeString());
Console.WriteLine("Клон:");
Console.WriteLine(clonedFamily.ToTreeString());
Console.WriteLine($"Кореневий об'єкт спільний: {ReferenceEquals(familyRoot, clonedFamily)}");
Console.WriteLine($"Перша дитина спільна: {ReferenceEquals(familyRoot.Children[0], clonedFamily.Children[0])}");
Console.WriteLine("Завдання 5. Будівельник");
var director = new CharacterDirector();
var dreamHero = director.CreateDreamHero(new HeroBuilder());
var worstEnemy = director.CreateArchEnemy(new EnemyBuilder());
Console.WriteLine(dreamHero);
Console.WriteLine();
Console.WriteLine(worstEnemy);