diff --git a/DesignPattern/DesignPattern.sln b/DesignPattern/DesignPattern.sln index 5750b17..0eca858 100644 --- a/DesignPattern/DesignPattern.sln +++ b/DesignPattern/DesignPattern.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Singleton", "Singleton\Sing EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Builder", "Builder\Builder.csproj", "{01181F37-48B4-4C0B-BE41-F8693C8B9E81}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Factory", "Factory\Factory.csproj", "{26FB406E-7EC9-4E6B-B115-68013563C935}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {01181F37-48B4-4C0B-BE41-F8693C8B9E81}.Debug|Any CPU.Build.0 = Debug|Any CPU {01181F37-48B4-4C0B-BE41-F8693C8B9E81}.Release|Any CPU.ActiveCfg = Release|Any CPU {01181F37-48B4-4C0B-BE41-F8693C8B9E81}.Release|Any CPU.Build.0 = Release|Any CPU + {26FB406E-7EC9-4E6B-B115-68013563C935}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DesignPattern/Factory/App.config b/DesignPattern/Factory/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DesignPattern/Factory/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DesignPattern/Factory/Factory.csproj b/DesignPattern/Factory/Factory.csproj new file mode 100644 index 0000000..179b490 --- /dev/null +++ b/DesignPattern/Factory/Factory.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {26FB406E-7EC9-4E6B-B115-68013563C935} + Exe + Factory + Factory + v4.8 + 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 diff --git a/DesignPattern/Factory/Program.cs b/DesignPattern/Factory/Program.cs new file mode 100644 index 0000000..f29d8b5 --- /dev/null +++ b/DesignPattern/Factory/Program.cs @@ -0,0 +1,25 @@ +using Factory.StaticFactoryMethod; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Factory +{ + /* + * 카테고리: 생성패턴 + * 개요: 객체를 직접 생성하는 대신 생성하는 기능을 가진 Factory 클래스를 통해 객체를 생성함. + * + */ + class Program + { + static void Main(string[] args) + { + // static factory method + ILogger logger = LoggerFactory.Create(LoggerType.DB); + + + } + } +} diff --git a/DesignPattern/Factory/Properties/AssemblyInfo.cs b/DesignPattern/Factory/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e51c77c --- /dev/null +++ b/DesignPattern/Factory/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("Factory")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Factory")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("26fb406e-7ec9-4e6b-b115-68013563c935")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Factory/StaticFactoryMethod/ILogger.cs b/DesignPattern/Factory/StaticFactoryMethod/ILogger.cs new file mode 100644 index 0000000..e159eed --- /dev/null +++ b/DesignPattern/Factory/StaticFactoryMethod/ILogger.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Factory.StaticFactoryMethod +{ + interface ILogger + { + + } +} diff --git a/DesignPattern/Factory/StaticFactoryMethod/Logger.cs b/DesignPattern/Factory/StaticFactoryMethod/Logger.cs new file mode 100644 index 0000000..1d918f9 --- /dev/null +++ b/DesignPattern/Factory/StaticFactoryMethod/Logger.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Factory.StaticFactoryMethod +{ + class DbLogger : ILogger { } + + class XmlLogger : ILogger { } + + class JsonLogger : ILogger { } +} diff --git a/DesignPattern/Factory/StaticFactoryMethod/LoggerFactory.cs b/DesignPattern/Factory/StaticFactoryMethod/LoggerFactory.cs new file mode 100644 index 0000000..69bf56e --- /dev/null +++ b/DesignPattern/Factory/StaticFactoryMethod/LoggerFactory.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Factory.StaticFactoryMethod +{ + public enum LoggerType + { + DB, + XML, + JSON + } + + class LoggerFactory + { + public static ILogger Create(LoggerType loggerType) + { + ILogger logger = null; + switch (loggerType) + { + case LoggerType.DB: + logger = new DbLogger(); + break; + case LoggerType.XML: + logger = new XmlLogger(); + break; + case LoggerType.JSON: + logger = new JsonLogger(); + break; + default: + throw new InvalidOperationException(); + } + + return logger; + } + } +}