Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4005efd

Browse files
prototype pattern example
1 parent 5896a58 commit 4005efd

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

‎DesignPatterns.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatePattern", "StatePatter
4747
EndProject
4848
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemplateMethodPattern", "TemplateMethodPattern\TemplateMethodPattern.csproj", "{611F5464-A5AD-4B27-86B1-5BD5EE0B3897}"
4949
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrototypePattern", "PrototypePattern\PrototypePattern.csproj", "{1E81873C-4A25-4F94-89B0-753C0FE4EB2F}"
51+
EndProject
5052
Global
5153
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5254
Debug|Any CPU = Debug|Any CPU
@@ -141,6 +143,10 @@ Global
141143
{611F5464-A5AD-4B27-86B1-5BD5EE0B3897}.Debug|Any CPU.Build.0 = Debug|Any CPU
142144
{611F5464-A5AD-4B27-86B1-5BD5EE0B3897}.Release|Any CPU.ActiveCfg = Release|Any CPU
143145
{611F5464-A5AD-4B27-86B1-5BD5EE0B3897}.Release|Any CPU.Build.0 = Release|Any CPU
146+
{1E81873C-4A25-4F94-89B0-753C0FE4EB2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
147+
{1E81873C-4A25-4F94-89B0-753C0FE4EB2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
148+
{1E81873C-4A25-4F94-89B0-753C0FE4EB2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
149+
{1E81873C-4A25-4F94-89B0-753C0FE4EB2F}.Release|Any CPU.Build.0 = Release|Any CPU
144150
EndGlobalSection
145151
GlobalSection(SolutionProperties) = preSolution
146152
HideSolutionNode = FALSE

‎PrototypePattern/Program.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
3+
namespace PrototypePattern
4+
{
5+
class Sheep
6+
{
7+
public string Name { get; set; }
8+
9+
public string Category { get; set; }
10+
11+
public Sheep(string name, string category)
12+
{
13+
Name = name;
14+
Category = category;
15+
}
16+
17+
public Sheep Clone()
18+
{
19+
return MemberwiseClone() as Sheep;
20+
}
21+
}
22+
23+
class Program
24+
{
25+
static void Main(string[] args)
26+
{
27+
var original = new Sheep("Jolly", "Mountain Sheep");
28+
Console.WriteLine(original.Name); // Jolly
29+
Console.WriteLine(original.Category); // Mountain Sheep
30+
31+
var cloned = original.Clone();
32+
cloned.Name = "Dolly";
33+
Console.WriteLine(cloned.Name); // Dolly
34+
Console.WriteLine(cloned.Category); // Mountain Sheep
35+
Console.WriteLine(original.Name); // Dolly
36+
37+
Console.ReadLine();
38+
}
39+
}
40+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /