From e1cd9a12961a2cbb651ee64706dcd7835a054f47 Mon Sep 17 00:00:00 2001 From: syneffort Date: Thu, 15 Sep 2022 18:08:04 +0900 Subject: [PATCH] template pattern --- DesignPattern/DesignPattern.sln | 6 ++ DesignPattern/Template/App.config | 6 ++ DesignPattern/Template/Client.cs | 20 +++++++ DesignPattern/Template/Letter.cs | 52 +++++++++++++++++ DesignPattern/Template/OfferLetter.cs | 21 +++++++ DesignPattern/Template/Program.cs | 23 ++++++++ .../Template/Properties/AssemblyInfo.cs | 36 ++++++++++++ DesignPattern/Template/SalesLetter.cs | 16 ++++++ DesignPattern/Template/Template.csproj | 57 +++++++++++++++++++ 9 files changed, 237 insertions(+) create mode 100644 DesignPattern/Template/App.config create mode 100644 DesignPattern/Template/Client.cs create mode 100644 DesignPattern/Template/Letter.cs create mode 100644 DesignPattern/Template/OfferLetter.cs create mode 100644 DesignPattern/Template/Program.cs create mode 100644 DesignPattern/Template/Properties/AssemblyInfo.cs create mode 100644 DesignPattern/Template/SalesLetter.cs create mode 100644 DesignPattern/Template/Template.csproj diff --git a/DesignPattern/DesignPattern.sln b/DesignPattern/DesignPattern.sln index 53ac36d..c2d4aa2 100644 --- a/DesignPattern/DesignPattern.sln +++ b/DesignPattern/DesignPattern.sln @@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainOfResponsibility", "Ch EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Command", "Command\Command.csproj", "{F34D75D4-7025-4CE3-AF7F-11117FA32F8B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Template", "Template\Template.csproj", "{8C1CA345-A2D4-46E2-9FD0-34E8BE4CE7C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -111,6 +113,10 @@ Global {F34D75D4-7025-4CE3-AF7F-11117FA32F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU {F34D75D4-7025-4CE3-AF7F-11117FA32F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU {F34D75D4-7025-4CE3-AF7F-11117FA32F8B}.Release|Any CPU.Build.0 = Release|Any CPU + {8C1CA345-A2D4-46E2-9FD0-34E8BE4CE7C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C1CA345-A2D4-46E2-9FD0-34E8BE4CE7C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C1CA345-A2D4-46E2-9FD0-34E8BE4CE7C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C1CA345-A2D4-46E2-9FD0-34E8BE4CE7C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DesignPattern/Template/App.config b/DesignPattern/Template/App.config new file mode 100644 index 0000000..aee9adf --- /dev/null +++ b/DesignPattern/Template/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DesignPattern/Template/Client.cs b/DesignPattern/Template/Client.cs new file mode 100644 index 0000000..631f9c8 --- /dev/null +++ b/DesignPattern/Template/Client.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Template +{ + internal class Client + { + public static void HowToTest() + { + Letter letter = new SalesLetter(); + letter.Send(); + + letter = new OfferLetter(); + letter.Send(); + } + } +} diff --git a/DesignPattern/Template/Letter.cs b/DesignPattern/Template/Letter.cs new file mode 100644 index 0000000..d490117 --- /dev/null +++ b/DesignPattern/Template/Letter.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Template +{ + // 베이스클래스 + internal abstract class Letter + { + public void Send() + { + CompanyLogo(); + Greeting(); + + Message(); + Offer(); + + Ending(); + Footer(); + } + + // 필수 + public abstract void Message(); + + // 옵션 + public virtual void Offer() { } + + + // 고정 메서드 들 + private void CompanyLogo() + { + Console.WriteLine("COMPANY LOGO"); + } + + private void Greeting() + { + Console.WriteLine("HELLO"); + } + + private void Ending() + { + Console.WriteLine("BYE"); + } + + private void Footer() + { + Console.WriteLine("WARM REGARD"); + } + } +} diff --git a/DesignPattern/Template/OfferLetter.cs b/DesignPattern/Template/OfferLetter.cs new file mode 100644 index 0000000..3848294 --- /dev/null +++ b/DesignPattern/Template/OfferLetter.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Template +{ + internal class OfferLetter : Letter + { + public override void Message() + { + Console.WriteLine("This is offer letter"); + } + + public override void Offer() + { + Console.WriteLine("This is our offer"); + } + } +} diff --git a/DesignPattern/Template/Program.cs b/DesignPattern/Template/Program.cs new file mode 100644 index 0000000..59d79cd --- /dev/null +++ b/DesignPattern/Template/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Template +{ + /* + * 카테고리: 행위 패턴 + * 개요: 메서드 중 일부 로직을 하위 서브클래스에서 재정의하도록 함 + * 베이스클래스에서 기본 골격 템플릿 코드를 만들어두고 서브클래스에서 일부 로직을 추가/수정함 + */ + internal class Program + { + static void Main(string[] args) + { + Client.HowToTest(); + + Console.ReadKey(); + } + } +} diff --git a/DesignPattern/Template/Properties/AssemblyInfo.cs b/DesignPattern/Template/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dab908e --- /dev/null +++ b/DesignPattern/Template/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("Template")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Template")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("8c1ca345-a2d4-46e2-9fd0-34e8be4ce7c4")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Template/SalesLetter.cs b/DesignPattern/Template/SalesLetter.cs new file mode 100644 index 0000000..38a5325 --- /dev/null +++ b/DesignPattern/Template/SalesLetter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Template +{ + internal class SalesLetter : Letter + { + public override void Message() + { + Console.WriteLine("This is sales letter"); + } + } +} diff --git a/DesignPattern/Template/Template.csproj b/DesignPattern/Template/Template.csproj new file mode 100644 index 0000000..c6f01d5 --- /dev/null +++ b/DesignPattern/Template/Template.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {8C1CA345-A2D4-46E2-9FD0-34E8BE4CE7C4} + Exe + Template + Template + v4.8.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file