-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
51 lines (39 loc) · 1.33 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
46
47
48
49
50
51
namespace DesignPatterns.Prototype;
public interface IEngine
{
IEngine Copy();
}
public class Machine
{
private readonly List<IEngine> _engines = new();
public void Add(IEngine engine) => _engines.Add(engine);
public List<IEngine> GetEngines() => _engines;
}
public class ViewEngine : IEngine
{
public ViewEngine(string name) => Console.WriteLine($"Engine name is: {name}");
public IEngine Copy() => this;
}
public class DataManagementEngine : IEngine
{
public DataManagementEngine(string name) => Console.WriteLine($"Engine name is: {name}");
public IEngine Copy() => this;
}
class App
{
public static void Main()
{
var machine = new Machine();
IEngine dataManagementEngine = new DataManagementEngine("Data Management Engine");
machine.Add(dataManagementEngine);
Console.WriteLine("Added data management instance");
machine.Add(dataManagementEngine.Copy());
Console.WriteLine("Added second data management instance (copy)");
IEngine viewEngine = new ViewEngine("View Engine");
machine.Add(viewEngine);
Console.WriteLine("Added view engine instance");
machine.Add(viewEngine.Copy());
Console.WriteLine("Added second view engine instance (copy)");
machine.GetEngines().ForEach(Console.WriteLine);
}
}