Skip to content

Commit b79bcef

Browse files
committed
[Builder/Decorator] - Refactor
1 parent 8848c1d commit b79bcef

14 files changed

+305
-243
lines changed

Builder/Builder.csproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@
4242
<Reference Include="System.Xml" />
4343
</ItemGroup>
4444
<ItemGroup>
45-
<Compile Include="Program.RealWorld.cs" />
46-
<Compile Include="Program.Structural.cs" />
45+
<Compile Include="RealWorld\CarBuilder.cs" />
46+
<Compile Include="RealWorld\IVehicleBuilder.cs" />
47+
<Compile Include="RealWorld\MotorCycleBuilder.cs" />
48+
<Compile Include="RealWorld\Program.cs" />
49+
<Compile Include="RealWorld\ScooterBuilder.cs" />
50+
<Compile Include="RealWorld\Shop.cs" />
51+
<Compile Include="RealWorld\Vehicle.cs" />
52+
<Compile Include="Structural\Program.Structural.cs" />
4753
<Compile Include="Properties\AssemblyInfo.cs" />
4854
</ItemGroup>
4955
<ItemGroup>

Builder/Program.RealWorld.cs

-235
This file was deleted.

Builder/RealWorld/CarBuilder.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
/// <summary>
3+
/// Separates object construction from its representation.
4+
///
5+
/// Separate the construction of a complex object from its representation so that
6+
/// the same construction process can create different representations.
7+
///
8+
/// Frequence of use: 2 medium low.
9+
/// </summary>
10+
namespace DoFactory.GangOfFour.Builder.RealWorld
11+
{
12+
/// <summary>
13+
/// The 'ConcreteBuilder2' class
14+
/// </summary>
15+
class CarBuilder : IVehicleBuilder
16+
{
17+
public Vehicle Vehicle { get; }
18+
19+
public CarBuilder()
20+
{
21+
Vehicle = new Vehicle("Car");
22+
}
23+
24+
public void BuildFrame()
25+
{
26+
Vehicle["frame"] = "Car Frame";
27+
}
28+
29+
public void BuildEngine()
30+
{
31+
Vehicle["engine"] = "2500 cc";
32+
}
33+
34+
public void BuildWheels()
35+
{
36+
Vehicle["wheels"] = "4";
37+
}
38+
39+
public void BuildDoors()
40+
{
41+
Vehicle["doors"] = "4";
42+
}
43+
}
44+
}

Builder/RealWorld/IVehicleBuilder.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace DoFactory.GangOfFour.Builder.RealWorld
2+
{
3+
interface IVehicleBuilder
4+
{
5+
Vehicle Vehicle { get; }
6+
7+
void BuildDoors();
8+
void BuildEngine();
9+
void BuildFrame();
10+
void BuildWheels();
11+
}
12+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
/// <summary>
3+
/// Separates object construction from its representation.
4+
///
5+
/// Separate the construction of a complex object from its representation so that
6+
/// the same construction process can create different representations.
7+
///
8+
/// Frequence of use: 2 medium low.
9+
/// </summary>
10+
namespace DoFactory.GangOfFour.Builder.RealWorld
11+
{
12+
/// <summary>
13+
/// The 'ConcreteBuilder1' class
14+
/// </summary>
15+
class MotorCycleBuilder : IVehicleBuilder
16+
{
17+
public Vehicle Vehicle { get; }
18+
19+
public MotorCycleBuilder()
20+
{
21+
Vehicle = new Vehicle("MotorCycle");
22+
}
23+
24+
public void BuildFrame()
25+
{
26+
Vehicle["frame"] = "MotorCycle Frame";
27+
}
28+
29+
public void BuildEngine()
30+
{
31+
Vehicle["engine"] = "500 cc";
32+
}
33+
34+
public void BuildWheels()
35+
{
36+
Vehicle["wheels"] = "2";
37+
}
38+
39+
public void BuildDoors()
40+
{
41+
Vehicle["doors"] = "0";
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)