Skip to content

Commit ccb6465

Browse files
author
anupavanm
committed
Bridge Pattern Example
1 parent 7155825 commit ccb6465

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

BridgePattern/BridgePattern.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>

BridgePattern/Program.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
3+
namespace BridgePattern
4+
{
5+
class Program
6+
{
7+
interface IWebPage
8+
{
9+
string GetContent();
10+
}
11+
12+
class About : IWebPage
13+
{
14+
protected ITheme theme;
15+
16+
public About(ITheme theme)
17+
{
18+
this.theme = theme;
19+
}
20+
21+
public string GetContent()
22+
{
23+
return String.Format("About page in {0}",theme.GetColor());
24+
}
25+
}
26+
27+
class Careers : IWebPage
28+
{
29+
protected ITheme theme;
30+
31+
public Careers(ITheme theme)
32+
{
33+
this.theme = theme;
34+
}
35+
36+
public string GetContent()
37+
{
38+
return String.Format("Careers page in {0}",theme.GetColor());
39+
}
40+
}
41+
42+
interface ITheme
43+
{
44+
string GetColor();
45+
}
46+
47+
class DarkTheme : ITheme
48+
{
49+
public string GetColor()
50+
{
51+
return "Dark Black";
52+
}
53+
}
54+
55+
class LightTheme : ITheme
56+
{
57+
public string GetColor()
58+
{
59+
return "Off White";
60+
}
61+
}
62+
63+
class AquaTheme : ITheme
64+
{
65+
public string GetColor()
66+
{
67+
return "Light blue";
68+
}
69+
}
70+
static void Main(string[] args)
71+
{
72+
var darkTheme = new DarkTheme();
73+
74+
var about= new About(darkTheme);
75+
var careers = new Careers(darkTheme);
76+
77+
Console.WriteLine(about.GetContent());
78+
Console.WriteLine(careers.GetContent());
79+
Console.ReadLine();
80+
}
81+
}
82+
}

DesignPatterns.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingletonPattern", "Singlet
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdapterPattern", "AdapterPattern\AdapterPattern.csproj", "{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BridgePattern", "BridgePattern\BridgePattern.csproj", "{8F9283E5-7EE1-4125-9CFB-FB6C380240D5}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
4547
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
4648
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
4749
{89CDD96A-D34A-41E8-A0A3-7B47C67C56CF}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{8F9283E5-7EE1-4125-9CFB-FB6C380240D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{8F9283E5-7EE1-4125-9CFB-FB6C380240D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{8F9283E5-7EE1-4125-9CFB-FB6C380240D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{8F9283E5-7EE1-4125-9CFB-FB6C380240D5}.Release|Any CPU.Build.0 = Release|Any CPU
4854
EndGlobalSection
4955
GlobalSection(SolutionProperties) = preSolution
5056
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)