Prototype pattern

remotes/origin/master
syneffort 3 years ago
parent f29f2ef0d2
commit ebe6726e2f
  1. 6
      DesignPattern/DesignPattern.sln
  2. 6
      DesignPattern/Prototype/App.config
  3. 22
      DesignPattern/Prototype/BasicWebPrototype.cs
  4. 29
      DesignPattern/Prototype/Client.cs
  5. 22
      DesignPattern/Prototype/PremiumWebPrototype.cs
  6. 23
      DesignPattern/Prototype/Program.cs
  7. 36
      DesignPattern/Prototype/Properties/AssemblyInfo.cs
  8. 21
      DesignPattern/Prototype/Prototype.cs
  9. 63
      DesignPattern/Prototype/Prototype.csproj
  10. 1
      DesignPattern/Prototype/basic.template
  11. 1
      DesignPattern/Prototype/premium.template

@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Builder", "Builder\Builder.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Factory", "Factory\Factory.csproj", "{26FB406E-7EC9-4E6B-B115-68013563C935}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prototype", "Prototype\Prototype.csproj", "{C5EFDAF1-61D2-4B66-BCE2-2A54632F3F7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ Global
{26FB406E-7EC9-4E6B-B115-68013563C935}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26FB406E-7EC9-4E6B-B115-68013563C935}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26FB406E-7EC9-4E6B-B115-68013563C935}.Release|Any CPU.Build.0 = Release|Any CPU
{C5EFDAF1-61D2-4B66-BCE2-2A54632F3F7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5EFDAF1-61D2-4B66-BCE2-2A54632F3F7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5EFDAF1-61D2-4B66-BCE2-2A54632F3F7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5EFDAF1-61D2-4B66-BCE2-2A54632F3F7A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prototype
{
class BasicWebPrototype : Prototype
{
public BasicWebPrototype()
{
WebTemplate = File.ReadAllText("basic.template");
}
public override Prototype Clone()
{
return (Prototype)this.MemberwiseClone();
}
}
}

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prototype
{
class Client
{
public static void HowToTest()
{
Prototype basicTemplate = new BasicWebPrototype();
Prototype premiumTemplate = new PremiumWebPrototype();
Prototype t1 = basicTemplate.Clone();
t1.SetTitle("Basic Web");
Console.WriteLine(t1.WebTemplate);
Prototype t2 = basicTemplate.Clone();
t2.SetTitle("Basic Web2");
Console.WriteLine(t2.WebTemplate);
Prototype t3 = premiumTemplate.Clone();
t3.SetTitle("Premium Web");
Console.WriteLine(t3.WebTemplate);
}
}
}

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prototype
{
class PremiumWebPrototype : Prototype
{
public PremiumWebPrototype()
{
WebTemplate = File.ReadAllText("premium.template");
}
public override Prototype Clone()
{
return (Prototype)this.MemberwiseClone();
}
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prototype
{
/*
* :
* : .
* .
*/
class Program
{
static void Main(string[] args)
{
Client.HowToTest();
Console.ReadKey();
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("Prototype")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Prototype")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("c5efdaf1-61d2-4b66-bce2-2a54632f3f7a")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prototype
{
public abstract class Prototype
{
// 필요에 따라 deep, shallow copy 선택하여 구현
public abstract Prototype Clone();
public string WebTemplate { get; protected set; }
public void SetTitle(string title)
{
this.WebTemplate = this.WebTemplate.Replace("{{title}}", title);
}
}
}

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C5EFDAF1-61D2-4B66-BCE2-2A54632F3F7A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Prototype</RootNamespace>
<AssemblyName>Prototype</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BasicWebPrototype.cs" />
<Compile Include="Client.cs" />
<Compile Include="PremiumWebPrototype.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Prototype.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="premium.template" />
<None Include="basic.template" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(ProjectDir)\basic.template" "$(targetDir)"
copy "$(ProjectDir)\premium.template" "$(targetDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
Loading…
Cancel
Save