class Client void Operation Prototype prototype new ConcretePrototype1

 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
class Client
{
void Operation()
{
Prototype prototype = new ConcretePrototype1(1);
Prototype clone = prototype.Clone();
prototype = new ConcretePrototype2(2);
clone = prototype.Clone();
}
}
abstract class Prototype
{
public int Id { get; private set; }
public Prototype(int id)
{
this.Id = id;
}
public abstract Prototype Clone();
}
class ConcretePrototype1 : Prototype
{
public ConcretePrototype1(int id)
: base(id)
{ }
public override Prototype Clone()
{
return new ConcretePrototype1(Id);
}
}
class ConcretePrototype2 : Prototype
{
public ConcretePrototype2(int id)
: base(id)
{ }
public override Prototype Clone()
{
return new ConcretePrototype2(Id);
}
}