diff --git a/DesignPattern/Bridge/App.config b/DesignPattern/Bridge/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DesignPattern/Bridge/App.config @@ -0,0 +1,6 @@ +๏ปฟ + + + + + \ No newline at end of file diff --git a/DesignPattern/Bridge/Bridge.csproj b/DesignPattern/Bridge/Bridge.csproj new file mode 100644 index 0000000..25dadc2 --- /dev/null +++ b/DesignPattern/Bridge/Bridge.csproj @@ -0,0 +1,59 @@ +๏ปฟ + + + + Debug + AnyCPU + {ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A} + Exe + Bridge + Bridge + 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/Bridge/Client.cs b/DesignPattern/Bridge/Client.cs new file mode 100644 index 0000000..ec70f68 --- /dev/null +++ b/DesignPattern/Bridge/Client.cs @@ -0,0 +1,27 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + class Client + { + public void HowToUse() + { + INetworkAbstraction net = new NetworkAbstraction(); + net.Network = GetNetwork(); + net.SendReceive(Encoding.UTF8.GetBytes("DATA ๐Ÿ”ฅ")); + } + + private INetworkImplementor GetNetwork() + { + Random rnd = new Random(); + if (rnd.Next() % 2 == 0) + return new WiFiImplementor(); + else + return new _4GImplementor(); + } + } +} diff --git a/DesignPattern/Bridge/INetworkAbstraction.cs b/DesignPattern/Bridge/INetworkAbstraction.cs new file mode 100644 index 0000000..d68cd62 --- /dev/null +++ b/DesignPattern/Bridge/INetworkAbstraction.cs @@ -0,0 +1,14 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + interface INetworkAbstraction + { + INetworkImplementor Network { get; set; } + void SendReceive(byte[] data); + } +} diff --git a/DesignPattern/Bridge/INetworkImplementor.cs b/DesignPattern/Bridge/INetworkImplementor.cs new file mode 100644 index 0000000..f862c3a --- /dev/null +++ b/DesignPattern/Bridge/INetworkImplementor.cs @@ -0,0 +1,16 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + interface INetworkImplementor + { + bool Connect(); + void Send(byte[] data); + byte[] Receive(); + bool Disconnect(); + } +} diff --git a/DesignPattern/Bridge/NetworkAbstraction.cs b/DesignPattern/Bridge/NetworkAbstraction.cs new file mode 100644 index 0000000..600700a --- /dev/null +++ b/DesignPattern/Bridge/NetworkAbstraction.cs @@ -0,0 +1,21 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + class NetworkAbstraction : INetworkAbstraction + { + public INetworkImplementor Network { get; set; } + + public void SendReceive(byte[] bytes) + { + this.Network.Connect(); + this.Network.Send(bytes); + bytes = this.Network.Receive(); + this.Network.Disconnect(); + } + } +} diff --git a/DesignPattern/Bridge/Program.cs b/DesignPattern/Bridge/Program.cs new file mode 100644 index 0000000..a285425 --- /dev/null +++ b/DesignPattern/Bridge/Program.cs @@ -0,0 +1,25 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + /* + * ์นดํ…Œ๊ณ ๋ฆฌ: ๊ตฌ์กฐํŒจํ„ด + * ๊ฐœ์š”: ์‹ค์ œ ๋กœ์ง์„ ๋‹ด์€ ๊ตฌํ˜„ ํด๋ž˜์Šค๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜๋Š” ๋Œ€์‹ , + * ๊ตฌํ˜„์ฒด๋กœ๋ถ€ํ„ฐ ์ถ”์ƒ์ธต ํด๋ž˜์Šค๋ฅผ ๋ถ„๋ฆฌํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ๋Š” ์ด ์ถ”์ƒ์ธต ํด๋ž˜์Šค๋ฅผ ๊ฑฐ์ณ ๊ตฌํ˜„ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•จ + * ์ด๋ฅผ ํ†ตํ•ด ํด๋ผ์ด์–ธํŠธ๋Š” ์—ฌ๋Ÿฌ ๊ตฌํ˜„์ฒด ์ค‘ ์–ด๋–ค ๊ตฌํ˜„์ฒด ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ง€ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Œ + */ + class Program + { + static void Main(string[] args) + { + Client client = new Client(); + client.HowToUse(); + + Console.ReadKey(); + } + } +} diff --git a/DesignPattern/Bridge/Properties/AssemblyInfo.cs b/DesignPattern/Bridge/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f530ad4 --- /dev/null +++ b/DesignPattern/Bridge/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +๏ปฟusing System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// ์–ด์…ˆ๋ธ”๋ฆฌ์— ๋Œ€ํ•œ ์ผ๋ฐ˜ ์ •๋ณด๋Š” ๋‹ค์Œ ํŠน์„ฑ ์ง‘ํ•ฉ์„ ํ†ตํ•ด +// ์ œ์–ด๋ฉ๋‹ˆ๋‹ค. ์–ด์…ˆ๋ธ”๋ฆฌ์™€ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜๋ ค๋ฉด +// ์ด๋Ÿฌํ•œ ํŠน์„ฑ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜์„ธ์š”. +[assembly: AssemblyTitle("Bridge")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Bridge")] +[assembly: AssemblyCopyright("Copyright ยฉ 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible์„ false๋กœ ์„ค์ •ํ•˜๋ฉด ์ด ์–ด์…ˆ๋ธ”๋ฆฌ์˜ ํ˜•์‹์ด COM ๊ตฌ์„ฑ ์š”์†Œ์— +// ํ‘œ์‹œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. COM์—์„œ ์ด ์–ด์…ˆ๋ธ”๋ฆฌ์˜ ํ˜•์‹์— ์•ก์„ธ์Šคํ•˜๋ ค๋ฉด +// ํ•ด๋‹น ํ˜•์‹์— ๋Œ€ํ•ด ComVisible ํŠน์„ฑ์„ true๋กœ ์„ค์ •ํ•˜์„ธ์š”. +[assembly: ComVisible(false)] + +// ์ด ํ”„๋กœ์ ํŠธ๊ฐ€ COM์— ๋…ธ์ถœ๋˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ GUID๋Š” typelib์˜ ID๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. +[assembly: Guid("abfd30c8-c2c5-4142-9e64-2cc65febbf7a")] + +// ์–ด์…ˆ๋ธ”๋ฆฌ์˜ ๋ฒ„์ „ ์ •๋ณด๋Š” ๋‹ค์Œ ๋„ค ๊ฐ€์ง€ ๊ฐ’์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค. +// +// ์ฃผ ๋ฒ„์ „ +// ๋ถ€ ๋ฒ„์ „ +// ๋นŒ๋“œ ๋ฒˆํ˜ธ +// ์ˆ˜์ • ๋ฒ„์ „ +// +// ๋ชจ๋“  ๊ฐ’์„ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ์•„๋ž˜์™€ ๊ฐ™์ด '*'๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋นŒ๋“œ ๋ฒˆํ˜ธ ๋ฐ ์ˆ˜์ • ๋ฒˆํ˜ธ๋ฅผ +// ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Bridge/WiFiImplementor.cs b/DesignPattern/Bridge/WiFiImplementor.cs new file mode 100644 index 0000000..00dffb1 --- /dev/null +++ b/DesignPattern/Bridge/WiFiImplementor.cs @@ -0,0 +1,40 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + class WiFiImplementor : INetworkImplementor + { + private byte[] data; + public bool Connect() + { + Console.WriteLine("WiFi: Connect"); + return true; + } + + public bool Disconnect() + { + Console.WriteLine("WiFi: Disconnect"); + return true; + } + + public byte[] Receive() + { + return this.data; + } + + public void Send(byte[] data) + { + this.data = data; + Console.WriteLine($"WiFi: Send"); + foreach (byte b in data) + { + Console.Write($"{b.ToString("X2")} "); + } + Console.WriteLine(); + } + } +} diff --git a/DesignPattern/Bridge/_4GImplementor.cs b/DesignPattern/Bridge/_4GImplementor.cs new file mode 100644 index 0000000..8c8be6c --- /dev/null +++ b/DesignPattern/Bridge/_4GImplementor.cs @@ -0,0 +1,40 @@ +๏ปฟusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bridge +{ + class _4GImplementor : INetworkImplementor + { + private byte[] data; + public bool Connect() + { + Console.WriteLine("4G: Connect"); + return true; + } + + public bool Disconnect() + { + Console.WriteLine("4G: Disconnect"); + return true; + } + + public byte[] Receive() + { + return data; + } + + public void Send(byte[] data) + { + this.data = data; + Console.WriteLine($"4G: Send"); + foreach (byte b in data) + { + Console.Write($"{b.ToString("X2")} "); + } + Console.WriteLine(); + } + } +} diff --git a/DesignPattern/DesignPattern.sln b/DesignPattern/DesignPattern.sln index 1453451..c66bcb0 100644 --- a/DesignPattern/DesignPattern.sln +++ b/DesignPattern/DesignPattern.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObjectPool", "ObjectPool\Ob EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adapter", "Adapter\Adapter.csproj", "{B7ADC626-22C7-4BE8-9385-ABA3AD428878}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bridge", "Bridge\Bridge.csproj", "{ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {B7ADC626-22C7-4BE8-9385-ABA3AD428878}.Debug|Any CPU.Build.0 = Debug|Any CPU {B7ADC626-22C7-4BE8-9385-ABA3AD428878}.Release|Any CPU.ActiveCfg = Release|Any CPU {B7ADC626-22C7-4BE8-9385-ABA3AD428878}.Release|Any CPU.Build.0 = Release|Any CPU + {ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE