-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathProgram.cs
40 lines (33 loc) · 800 Bytes
/
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
using System;
namespace PrototypePattern
{
class Sheep
{
public string Name { get; set; }
public string Category { get; set; }
public Sheep(string name, string category)
{
Name = name;
Category = category;
}
public Sheep Clone()
{
return MemberwiseClone() as Sheep;
}
}
class Program
{
static void Main(string[] args)
{
var original = new Sheep("Jolly", "Mountain Sheep");
Console.WriteLine(original.Name); // Jolly
Console.WriteLine(original.Category); // Mountain Sheep
var cloned = original.Clone();
cloned.Name = "Dolly";
Console.WriteLine(cloned.Name); // Dolly
Console.WriteLine(cloned.Category); // Mountain Sheep
Console.WriteLine(original.Name); // Dolly
Console.ReadLine();
}
}
}