Skip to content

Commit 95989af

Browse files
committed
Bridge Design Pattern
1 parent b4ee876 commit 95989af

27 files changed

+364
-0
lines changed

Bridge/Bridge.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

Bridge/Program.cs

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Decouple an abstraction from its implementation so that the two can vary independently
2+
3+
/// <summary>
4+
/// Refined abstraction method is a bridge between the abstraction and implementation by changing it's behaviour
5+
/// </summary>
6+
7+
8+
RecipeBase recipe = new RefinedRecipe();
9+
10+
//set cook as John and cook
11+
recipe.Cook = new JohnCook();
12+
recipe.Boil();
13+
recipe.Fry();
14+
15+
//change cook to Branden and cook
16+
//now you can assign a new cook to the cook independently
17+
recipe.Cook = new BrandenCook();
18+
recipe.Boil();
19+
recipe.Fry();
20+
21+
/// <summary>
22+
/// Abstract Class
23+
/// </summary>
24+
public class RecipeBase
25+
{
26+
27+
private Cook cook;
28+
29+
public Cook Cook
30+
{
31+
set { cook = value; }
32+
}
33+
34+
public virtual void Boil()
35+
{
36+
cook.Boil();
37+
}
38+
39+
public virtual void Fry()
40+
{
41+
cook.Fry();
42+
}
43+
}
44+
45+
/// <summary>
46+
/// Refined Abstract class with which you can redefine the abstract methods (this is working as a bridge between an abstraction and implementation)
47+
/// </summary>
48+
public class RefinedRecipe : RecipeBase
49+
{
50+
public override void Boil()
51+
{
52+
Console.WriteLine();
53+
Console.WriteLine("===================Boil Start===============");
54+
base.Boil();
55+
Console.WriteLine("===================Boil End=================");
56+
Console.WriteLine();
57+
}
58+
59+
public override void Fry()
60+
{
61+
Console.WriteLine();
62+
Console.WriteLine("===================Fry Start=================");
63+
base.Fry();
64+
Console.WriteLine("===================Fry End===================");
65+
Console.WriteLine();
66+
}
67+
}
68+
public abstract class Cook
69+
{
70+
public abstract void Boil();
71+
public abstract void Fry();
72+
}
73+
74+
public class JohnCook : Cook
75+
{
76+
public override void Boil()
77+
{
78+
Console.WriteLine("John is Boiling");
79+
}
80+
81+
public override void Fry()
82+
{
83+
Console.WriteLine("John is Frying");
84+
}
85+
}
86+
87+
public class BrandenCook : Cook
88+
{
89+
public override void Boil()
90+
{
91+
Console.WriteLine("Branden is Boiling");
92+
}
93+
94+
public override void Fry()
95+
{
96+
Console.WriteLine("Branden is Frying");
97+
}
98+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"runtimeTarget": {
3+
"name": ".NETCoreApp,Version=v6.0",
4+
"signature": ""
5+
},
6+
"compilationOptions": {},
7+
"targets": {
8+
".NETCoreApp,Version=v6.0": {
9+
"Bridge/1.0.0": {
10+
"runtime": {
11+
"Bridge.dll": {}
12+
}
13+
}
14+
}
15+
},
16+
"libraries": {
17+
"Bridge/1.0.0": {
18+
"type": "project",
19+
"serviceable": false,
20+
"sha512": ""
21+
}
22+
}
23+
}

Bridge/bin/Debug/net6.0/Bridge.dll

6 KB
Binary file not shown.

Bridge/bin/Debug/net6.0/Bridge.exe

146 KB
Binary file not shown.

Bridge/bin/Debug/net6.0/Bridge.pdb

10.6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"runtimeOptions": {
3+
"tfm": "net6.0",
4+
"framework": {
5+
"name": "Microsoft.NETCore.App",
6+
"version": "6.0.0"
7+
}
8+
}
9+
}
6 KB
Binary file not shown.
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"format": 1,
3+
"restore": {
4+
"C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj": {}
5+
},
6+
"projects": {
7+
"C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj": {
8+
"version": "1.0.0",
9+
"restore": {
10+
"projectUniqueName": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj",
11+
"projectName": "Bridge",
12+
"projectPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj",
13+
"packagesPath": "C:\\Users\\EdenP\\.nuget\\packages\\",
14+
"outputPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\obj\\",
15+
"projectStyle": "PackageReference",
16+
"fallbackFolders": [
17+
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
18+
],
19+
"configFilePaths": [
20+
"C:\\Users\\EdenP\\AppData\\Roaming\\NuGet\\NuGet.Config",
21+
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
22+
],
23+
"originalTargetFrameworks": [
24+
"net6.0"
25+
],
26+
"sources": {
27+
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
28+
"https://api.nuget.org/v3/index.json": {}
29+
},
30+
"frameworks": {
31+
"net6.0": {
32+
"targetAlias": "net6.0",
33+
"projectReferences": {}
34+
}
35+
},
36+
"warningProperties": {
37+
"warnAsError": [
38+
"NU1605"
39+
]
40+
}
41+
},
42+
"frameworks": {
43+
"net6.0": {
44+
"targetAlias": "net6.0",
45+
"imports": [
46+
"net461",
47+
"net462",
48+
"net47",
49+
"net471",
50+
"net472",
51+
"net48"
52+
],
53+
"assetTargetFallback": true,
54+
"warn": true,
55+
"frameworkReferences": {
56+
"Microsoft.NETCore.App": {
57+
"privateAssets": "all"
58+
}
59+
},
60+
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.105\\RuntimeIdentifierGraph.json"
61+
}
62+
}
63+
}
64+
}
65+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
4+
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
5+
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
6+
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
7+
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
8+
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\EdenP\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
9+
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
10+
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.0.0</NuGetToolVersion>
11+
</PropertyGroup>
12+
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
13+
<SourceRoot Include="C:\Users\EdenP\.nuget\packages\" />
14+
<SourceRoot Include="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\" />
15+
</ItemGroup>
16+
</Project>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// <autogenerated />
2+
using System;
3+
using System.Reflection;
4+
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
using System;
11+
using System.Reflection;
12+
13+
[assembly: System.Reflection.AssemblyCompanyAttribute("Bridge")]
14+
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
15+
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
16+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
17+
[assembly: System.Reflection.AssemblyProductAttribute("Bridge")]
18+
[assembly: System.Reflection.AssemblyTitleAttribute("Bridge")]
19+
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
20+
21+
// Generated by the MSBuild WriteCodeFragment class.
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a2588e96b6e73ca0dd8c8481d4a80be26970282f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
is_global = true
2+
build_property.TargetFramework = net6.0
3+
build_property.TargetPlatformMinVersion =
4+
build_property.UsingMicrosoftNETSdkWeb =
5+
build_property.ProjectTypeGuids =
6+
build_property.InvariantGlobalization =
7+
build_property.PlatformNeutralAssembly =
8+
build_property._SupportedPlatformList = Linux,macOS,Windows
9+
build_property.RootNamespace = Bridge
10+
build_property.ProjectDir = C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// <auto-generated/>
2+
global using global::System;
3+
global using global::System.Collections.Generic;
4+
global using global::System.IO;
5+
global using global::System.Linq;
6+
global using global::System.Net.Http;
7+
global using global::System.Threading;
8+
global using global::System.Threading.Tasks;
192 Bytes
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a4cc8dc7e16a4cfdee1c34cb65153d926206d72d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\bin\Debug\net6.0\Bridge.exe
2+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\bin\Debug\net6.0\Bridge.deps.json
3+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\bin\Debug\net6.0\Bridge.runtimeconfig.json
4+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\bin\Debug\net6.0\Bridge.dll
5+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\bin\Debug\net6.0\ref\Bridge.dll
6+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\bin\Debug\net6.0\Bridge.pdb
7+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.csproj.AssemblyReference.cache
8+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.GeneratedMSBuildEditorConfig.editorconfig
9+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.AssemblyInfoInputs.cache
10+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.AssemblyInfo.cs
11+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.csproj.CoreCompileInputs.cache
12+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.dll
13+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\ref\Bridge.dll
14+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.pdb
15+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Bridge\obj\Debug\net6.0\Bridge.genruntimeconfig.cache

Bridge/obj/Debug/net6.0/Bridge.dll

6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
faf48ad503ad888814f4f65460512297197721ec

Bridge/obj/Debug/net6.0/Bridge.pdb

10.6 KB
Binary file not shown.

Bridge/obj/Debug/net6.0/apphost.exe

146 KB
Binary file not shown.
6 KB
Binary file not shown.

Bridge/obj/project.assets.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"version": 3,
3+
"targets": {
4+
"net6.0": {}
5+
},
6+
"libraries": {},
7+
"projectFileDependencyGroups": {
8+
"net6.0": []
9+
},
10+
"packageFolders": {
11+
"C:\\Users\\EdenP\\.nuget\\packages\\": {},
12+
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
13+
},
14+
"project": {
15+
"version": "1.0.0",
16+
"restore": {
17+
"projectUniqueName": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj",
18+
"projectName": "Bridge",
19+
"projectPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj",
20+
"packagesPath": "C:\\Users\\EdenP\\.nuget\\packages\\",
21+
"outputPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\obj\\",
22+
"projectStyle": "PackageReference",
23+
"fallbackFolders": [
24+
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
25+
],
26+
"configFilePaths": [
27+
"C:\\Users\\EdenP\\AppData\\Roaming\\NuGet\\NuGet.Config",
28+
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
29+
],
30+
"originalTargetFrameworks": [
31+
"net6.0"
32+
],
33+
"sources": {
34+
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
35+
"https://api.nuget.org/v3/index.json": {}
36+
},
37+
"frameworks": {
38+
"net6.0": {
39+
"targetAlias": "net6.0",
40+
"projectReferences": {}
41+
}
42+
},
43+
"warningProperties": {
44+
"warnAsError": [
45+
"NU1605"
46+
]
47+
}
48+
},
49+
"frameworks": {
50+
"net6.0": {
51+
"targetAlias": "net6.0",
52+
"imports": [
53+
"net461",
54+
"net462",
55+
"net47",
56+
"net471",
57+
"net472",
58+
"net48"
59+
],
60+
"assetTargetFallback": true,
61+
"warn": true,
62+
"frameworkReferences": {
63+
"Microsoft.NETCore.App": {
64+
"privateAssets": "all"
65+
}
66+
},
67+
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.105\\RuntimeIdentifierGraph.json"
68+
}
69+
}
70+
}
71+
}

Bridge/obj/project.nuget.cache

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": 2,
3+
"dgSpecHash": "sT2kKV4D65QGNy77T80COV3OilN35UM31wPpuXgb9dli2k9pY5wGX3ICi4RoZqWX9sG0Ti+yy/a1LOMQwt/qkw==",
4+
"success": true,
5+
"projectFilePath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Bridge\\Bridge.csproj",
6+
"expectedPackageFiles": [],
7+
"logs": []
8+
}

0 commit comments

Comments
 (0)