Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7155825

Browse files
author
anupavanm
committed
Adapter pattern example
1 parent b627c95 commit 7155825

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

‎AdapterPattern/AdapterPattern.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

‎AdapterPattern/Program.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
3+
namespace AdapterPattern
4+
{
5+
interface ILion
6+
{
7+
void Roar();
8+
}
9+
10+
class AfricanLion : ILion
11+
{
12+
public void Roar()
13+
{
14+
15+
}
16+
}
17+
18+
class AsiaLion : ILion
19+
{
20+
public void Roar()
21+
{
22+
23+
}
24+
}
25+
26+
// This needs to be added to the game
27+
class WildDog
28+
{
29+
public void bark()
30+
{
31+
}
32+
}
33+
34+
// Adapter around wild dog to make it compatible with our game
35+
class WildDogAdapter : ILion
36+
{
37+
private WildDog mDog;
38+
public WildDogAdapter(WildDog dog)
39+
{
40+
this.mDog = dog;
41+
}
42+
public void Roar()
43+
{
44+
mDog.bark();
45+
}
46+
}
47+
48+
class Hunter
49+
{
50+
public void Hunt(ILion lion)
51+
{
52+
53+
}
54+
}
55+
56+
class Program
57+
{
58+
static void Main(string[] args)
59+
{
60+
var wildDog = new WildDog();
61+
var wildDogAdapter = new WildDogAdapter(wildDog);
62+
63+
var hunter = new Hunter();
64+
hunter.Hunt(wildDogAdapter);
65+
66+
Console.ReadLine();
67+
}
68+
}
69+
}

‎DesignPatterns.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuilderPattern", "BuilderPa
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingletonPattern", "SingletonPattern\SingletonPattern.csproj", "{A61E958E-B6C9-413F-BACA-EA23D38A7DF2}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdapterPattern", "AdapterPattern\AdapterPattern.csproj", "{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
3941
{A61E958E-B6C9-413F-BACA-EA23D38A7DF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{A61E958E-B6C9-413F-BACA-EA23D38A7DF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{A61E958E-B6C9-413F-BACA-EA23D38A7DF2}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /