-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (92 loc) · 2.58 KB
/
Program.cs
File metadata and controls
105 lines (92 loc) · 2.58 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
/*
* Author: Nikolay Dvurechensky
* Site: https://dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 27 апреля 2026 09:40:39
* Version: 1.0.254
*/
/* Приспособленец
Благодаря совместному использованию,
поддерживает эффективную работу
с большим количеством объектов.
(для оптимизации работы с памятью)
*/
class Program
{
static void Main()
{
#region Пример №1 - базовое
double longtitude = 22.33;
double latitude = 55.11;
HouseFactory houseFactory = new HouseFactory();
for (int i = 0; i < 10; i++)
{
House panelH = houseFactory.GetHouse("Panel");
if(panelH != null)
panelH.Build(longtitude, latitude);
longtitude += 0.1;
latitude += 0.1;
}
for (int i = 0; i < 10; i++)
{
House officeH = houseFactory.GetHouse("Office");
if (officeH != null)
officeH.Build(longtitude, latitude);
longtitude += 0.1;
latitude += 0.1;
}
Console.ReadKey();
#endregion
}
}
abstract class House
{
/// <summary>
/// Кол-во этажей - внутреннее состояние
/// </summary>
protected int stages;
/// <summary>
/// Внешнее состояние действия
/// </summary>
/// <param name="latitude"></param>
/// <param name="longitude"></param>
public abstract void Build(double latitude, double longitude);
}
class PanelHouse : House
{
public PanelHouse()
{
stages = 5;
}
public override void Build(double latitude, double longitude)
{
Console.WriteLine($"PanelHouse Build stages-{stages} {latitude}, {longitude}");
}
}
class OfficeHouse : House
{
public OfficeHouse()
{
stages = 50;
}
public override void Build(double latitude, double longitude)
{
Console.WriteLine($"OfficeHouse Build stages-{stages} {latitude}, {longitude}");
}
}
class HouseFactory
{
Dictionary<string, House> houses = new Dictionary<string, House>();
public HouseFactory()
{
houses.Add("Panel", new PanelHouse());
houses.Add("Office", new OfficeHouse());
}
public House GetHouse(string key)
{
if (houses.ContainsKey(key))
return houses[key];
else
return null;
}
}