Skip to content

Commit 4a217bb

Browse files
committed
Facede pattern example
1 parent 73875d4 commit 4a217bb

File tree

3 files changed

+100
-8
lines changed

3 files changed

+100
-8
lines changed

DesignPatterns.sln

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.27004.2009
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern", "FactoryPattern\FactoryPattern.csproj", "{EC684E1B-EA3F-47FD-8F45-175C56667F13}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FactoryPattern", "FactoryPattern\FactoryPattern.csproj", "{EC684E1B-EA3F-47FD-8F45-175C56667F13}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryMethodPattern", "FactoryMethodPattern\FactoryMethodPattern.csproj", "{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FactoryMethodPattern", "FactoryMethodPattern\FactoryMethodPattern.csproj", "{493DBC90-47D2-49F5-906D-14F3AFDDF9F8}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFactoryPattern", "AbstractFactoryPattern\AbstractFactoryPattern.csproj", "{081F04C5-CF9E-4997-B04E-5F9FDCCEE90D}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFactoryPattern", "AbstractFactoryPattern\AbstractFactoryPattern.csproj", "{081F04C5-CF9E-4997-B04E-5F9FDCCEE90D}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuilderPattern", "BuilderPattern\BuilderPattern.csproj", "{A2804858-D1F9-4849-8C7E-1AB4DA7F979E}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuilderPattern", "BuilderPattern\BuilderPattern.csproj", "{A2804858-D1F9-4849-8C7E-1AB4DA7F979E}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingletonPattern", "SingletonPattern\SingletonPattern.csproj", "{A61E958E-B6C9-413F-BACA-EA23D38A7DF2}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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}"
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BridgePattern", "BridgePattern\BridgePattern.csproj", "{8F9283E5-7EE1-4125-9CFB-FB6C380240D5}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompositePattern", "CompositePattern\CompositePattern.csproj", "{3CFAA453-5386-4A9E-9DDA-20A0DC8F700D}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompositePattern", "CompositePattern\CompositePattern.csproj", "{3CFAA453-5386-4A9E-9DDA-20A0DC8F700D}"
21+
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FacadePattern", "FacadePattern\FacadePattern.csproj", "{8E91875D-E79F-4D16-9FFC-49BD5BE7DF03}"
2123
EndProject
2224
Global
2325
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -57,6 +59,10 @@ Global
5759
{3CFAA453-5386-4A9E-9DDA-20A0DC8F700D}.Debug|Any CPU.Build.0 = Debug|Any CPU
5860
{3CFAA453-5386-4A9E-9DDA-20A0DC8F700D}.Release|Any CPU.ActiveCfg = Release|Any CPU
5961
{3CFAA453-5386-4A9E-9DDA-20A0DC8F700D}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{8E91875D-E79F-4D16-9FFC-49BD5BE7DF03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{8E91875D-E79F-4D16-9FFC-49BD5BE7DF03}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{8E91875D-E79F-4D16-9FFC-49BD5BE7DF03}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{8E91875D-E79F-4D16-9FFC-49BD5BE7DF03}.Release|Any CPU.Build.0 = Release|Any CPU
6066
EndGlobalSection
6167
GlobalSection(SolutionProperties) = preSolution
6268
HideSolutionNode = FALSE

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

FacadePattern/Program.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
3+
namespace FacadePattern
4+
{
5+
class Computer
6+
{
7+
public void GetElectricShock()
8+
{
9+
Console.Write("Ouch!");
10+
}
11+
12+
public void MakeSound()
13+
{
14+
Console.Write("Beep beep!");
15+
}
16+
17+
public void ShowLoadingScreen()
18+
{
19+
Console.Write("Loading..");
20+
}
21+
22+
public void Bam()
23+
{
24+
Console.Write("Ready to be used!");
25+
}
26+
27+
public void CloseEverything()
28+
{
29+
Console.Write("Bup bup bup buzzzz!");
30+
}
31+
32+
public void Sooth()
33+
{
34+
Console.Write("Zzzzz");
35+
}
36+
37+
public void PullCurrent()
38+
{
39+
Console.Write("Haaah!");
40+
}
41+
}
42+
43+
class ComputerFacade
44+
{
45+
private readonly Computer mComputer;
46+
47+
public ComputerFacade(Computer computer)
48+
{
49+
this.mComputer = computer ?? throw new ArgumentNullException("computer", "computer cannot be null");
50+
}
51+
52+
public void TurnOn()
53+
{
54+
mComputer.GetElectricShock();
55+
mComputer.MakeSound();
56+
mComputer.ShowLoadingScreen();
57+
mComputer.Bam();
58+
}
59+
60+
public void TurnOff()
61+
{
62+
mComputer.CloseEverything();
63+
mComputer.PullCurrent();
64+
mComputer.Sooth();
65+
}
66+
}
67+
class Program
68+
{
69+
static void Main(string[] args)
70+
{
71+
var computer = new ComputerFacade(new Computer());
72+
computer.TurnOn(); // Ouch! Beep beep! Loading.. Ready to be used!
73+
Console.WriteLine();
74+
computer.TurnOff(); // Bup bup buzzz! Haah! Zzzzz
75+
Console.ReadLine();
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)