bridge pattern

remotes/origin/master
syneffort 3 years ago
parent 94953489c4
commit ea0c1c19d3
  1. 6
      DesignPattern/Bridge/App.config
  2. 59
      DesignPattern/Bridge/Bridge.csproj
  3. 27
      DesignPattern/Bridge/Client.cs
  4. 14
      DesignPattern/Bridge/INetworkAbstraction.cs
  5. 16
      DesignPattern/Bridge/INetworkImplementor.cs
  6. 21
      DesignPattern/Bridge/NetworkAbstraction.cs
  7. 25
      DesignPattern/Bridge/Program.cs
  8. 36
      DesignPattern/Bridge/Properties/AssemblyInfo.cs
  9. 40
      DesignPattern/Bridge/WiFiImplementor.cs
  10. 40
      DesignPattern/Bridge/_4GImplementor.cs
  11. 6
      DesignPattern/DesignPattern.sln

@ -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,59 @@
<?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>{ABFD30C8-C2C5-4142-9E64-2CC65FEBBF7A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Bridge</RootNamespace>
<AssemblyName>Bridge</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="Client.cs" />
<Compile Include="INetworkAbstraction.cs" />
<Compile Include="INetworkImplementor.cs" />
<Compile Include="NetworkAbstraction.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WiFiImplementor.cs" />
<Compile Include="_4GImplementor.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -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();
}
}
}

@ -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);
}
}

@ -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();
}
}

@ -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();
}
}
}

@ -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();
}
}
}

@ -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")]

@ -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();
}
}
}

@ -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();
}
}
}

@ -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

Loading…
Cancel
Save