diff --git a/DesignPattern/DesignPattern.sln b/DesignPattern/DesignPattern.sln index 9658118..8b7bb9d 100644 --- a/DesignPattern/DesignPattern.sln +++ b/DesignPattern/DesignPattern.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Composite", "Composite\Comp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decorator", "Decorator\Decorator.csproj", "{4BDF9142-7984-485F-AA62-77B7B7359966}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facade", "Facade\Facade.csproj", "{968D6295-75C3-46FF-AAB9-1579DB405B31}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,6 +65,10 @@ Global {4BDF9142-7984-485F-AA62-77B7B7359966}.Debug|Any CPU.Build.0 = Debug|Any CPU {4BDF9142-7984-485F-AA62-77B7B7359966}.Release|Any CPU.ActiveCfg = Release|Any CPU {4BDF9142-7984-485F-AA62-77B7B7359966}.Release|Any CPU.Build.0 = Release|Any CPU + {968D6295-75C3-46FF-AAB9-1579DB405B31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {968D6295-75C3-46FF-AAB9-1579DB405B31}.Debug|Any CPU.Build.0 = Debug|Any CPU + {968D6295-75C3-46FF-AAB9-1579DB405B31}.Release|Any CPU.ActiveCfg = Release|Any CPU + {968D6295-75C3-46FF-AAB9-1579DB405B31}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DesignPattern/Facade/App.config b/DesignPattern/Facade/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DesignPattern/Facade/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DesignPattern/Facade/Client.cs b/DesignPattern/Facade/Client.cs new file mode 100644 index 0000000..edccea6 --- /dev/null +++ b/DesignPattern/Facade/Client.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Facade +{ + class Client + { + public static void HowToUse() + { + GC.Collect(); + + byte[] data = Facade.PrintPicture(102802); + + Form form = new Form(); + form.BackgroundImageLayout = ImageLayout.Stretch; + form.BackgroundImage = GenerateBitmapImage(data); + form.ShowDialog(); + } + + private static Bitmap GenerateBitmapImage(byte[] data) + { + int size = (int)Math.Sqrt(data.Length); + + Bitmap bitmap = new Bitmap(size, size, PixelFormat.Format8bppIndexed); + BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); + + try + { + for (int rowIdx = 0; rowIdx < bitmapData.Height; ++rowIdx) + { + Marshal.Copy(data, rowIdx * bitmap.Width, bitmapData.Scan0 + rowIdx * bitmapData.Stride, bitmap.Width); + } + } + finally + { + bitmap.UnlockBits(bitmapData); + } + + return bitmap; + } + } +} diff --git a/DesignPattern/Facade/Facade.cs b/DesignPattern/Facade/Facade.cs new file mode 100644 index 0000000..4d553fc --- /dev/null +++ b/DesignPattern/Facade/Facade.cs @@ -0,0 +1,24 @@ +using Facade.Subsystems; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Facade +{ + class Facade + { + public static byte[] PrintPicture(int employeeId) + { + HRSystem hr = new HRSystem(); + int picId = hr.GetPictureId(employeeId); + + PictureSystem pic = new PictureSystem(); + byte[] picData = pic.GetPicture(picId); + + PrintSystem prt = new PrintSystem(); + return prt.Print(picData); + } + } +} diff --git a/DesignPattern/Facade/Facade.csproj b/DesignPattern/Facade/Facade.csproj new file mode 100644 index 0000000..f88cc5d --- /dev/null +++ b/DesignPattern/Facade/Facade.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {968D6295-75C3-46FF-AAB9-1579DB405B31} + Exe + Facade + Facade + 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/Facade/Program.cs b/DesignPattern/Facade/Program.cs new file mode 100644 index 0000000..9c47ad2 --- /dev/null +++ b/DesignPattern/Facade/Program.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Facade +{ + /* + * 카테고리: 구조 패턴 + * 개요: 복잡하고 커다란 서브시스템을 간단한 인터페이스를 통해 사용이 쉽도록 함 + * 클라이언트는 패턴을 통해 전면의 단순 인터페이스만 사용하므로, + * 서브시스템 라이브러리 사용의 가독성, 사용도를 높임 + * + * 참고: Adapter 패턴과 유사하지만, + * Adapter는 클라이언트가 필요로 하는 다른 인터페이스로 변환하는 것이고 + * Facade는 서브시스템을 쉽게 사용할 수 있는 간단한 인터페이스를 제공하는 것임 + */ + class Program + { + static void Main(string[] args) + { + Client.HowToUse(); + + Console.ReadKey(); + } + } +} diff --git a/DesignPattern/Facade/Properties/AssemblyInfo.cs b/DesignPattern/Facade/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..842e18f --- /dev/null +++ b/DesignPattern/Facade/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("Facade")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Facade")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("968d6295-75c3-46ff-aab9-1579db405b31")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Facade/Subsystems/HRSystem.cs b/DesignPattern/Facade/Subsystems/HRSystem.cs new file mode 100644 index 0000000..5df633b --- /dev/null +++ b/DesignPattern/Facade/Subsystems/HRSystem.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Facade.Subsystems +{ + class HRSystem + { + public int GetPictureId(int empId) + { + return empId; + } + } +} diff --git a/DesignPattern/Facade/Subsystems/PictureSystem.cs b/DesignPattern/Facade/Subsystems/PictureSystem.cs new file mode 100644 index 0000000..78c43b6 --- /dev/null +++ b/DesignPattern/Facade/Subsystems/PictureSystem.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Facade.Subsystems +{ + class PictureSystem + { + Random rand = new Random(); + + public byte[] GetPicture(int id) + { + byte[] data = new byte[id]; + rand.NextBytes(data); + + return data; + } + } +} diff --git a/DesignPattern/Facade/Subsystems/PrintSystem.cs b/DesignPattern/Facade/Subsystems/PrintSystem.cs new file mode 100644 index 0000000..0d5245a --- /dev/null +++ b/DesignPattern/Facade/Subsystems/PrintSystem.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Facade.Subsystems +{ + class PrintSystem + { + public byte[] Print(byte[] data) + { + Console.WriteLine(String.Concat(data.Select(b => string.Format("[{0}]", b.ToString("X2"))))); + + + return data; + } + } +}