Skip to content

Commit 6a4d9d5

Browse files
committed
Build Pattern
1 parent 20b76d6 commit 6a4d9d5

27 files changed

+366
-0
lines changed

Builder/Builder.csproj

Lines changed: 10 additions & 0 deletions
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>

Builder/Program.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+

2+
class Program
3+
{
4+
static void Main(string[] args)
5+
{
6+
//Builder design pattern separates the concern of creating or building a complex object from its representation
7+
//so that the same construction process can create different representations
8+
9+
Director director = new Director();
10+
11+
Builder iphoneBuilder = new IphoneBuilder();
12+
Builder samsungBuilder = new SamsungBuilder();
13+
14+
director.Construct(iphoneBuilder);
15+
CellPhone iphoneProduct = iphoneBuilder.GetResult();
16+
iphoneProduct.Show();
17+
18+
director.Construct(samsungBuilder);
19+
CellPhone samsungProduct = samsungBuilder.GetResult();
20+
samsungProduct.Show();
21+
}
22+
}
23+
24+
25+
class Director
26+
{
27+
public void Construct(Builder builder)
28+
{
29+
builder.BuildBattery();
30+
builder.BuildScreen();
31+
}
32+
}
33+
34+
abstract class Builder
35+
{
36+
public abstract void BuildScreen();
37+
public abstract void BuildBattery();
38+
public abstract CellPhone GetResult();
39+
}
40+
41+
class IphoneBuilder : Builder
42+
{
43+
private CellPhone cellPhone = new CellPhone();
44+
45+
public override void BuildScreen()
46+
{
47+
cellPhone.Add("Iphone Screen");
48+
}
49+
public override void BuildBattery()
50+
{
51+
cellPhone.Add("Iphone Battery");
52+
}
53+
public override CellPhone GetResult()
54+
{
55+
return cellPhone;
56+
}
57+
58+
}
59+
60+
class SamsungBuilder : Builder
61+
{
62+
private CellPhone cellPhone = new CellPhone();
63+
64+
public override void BuildBattery()
65+
{
66+
cellPhone.Add("Samsung Battery");
67+
}
68+
public override void BuildScreen()
69+
{
70+
cellPhone.Add("Samsung Screen");
71+
}
72+
public override CellPhone GetResult()
73+
{
74+
return cellPhone;
75+
}
76+
77+
78+
}
79+
80+
class CellPhone
81+
{
82+
private List<string> parts = new List<string>();
83+
84+
public void Add(string part)
85+
{
86+
parts.Add(part);
87+
}
88+
89+
public void Show()
90+
{
91+
Console.WriteLine("\n==============================");
92+
Console.WriteLine(" CellPhone Parts \n");
93+
foreach (string part in parts)
94+
{
95+
Console.WriteLine(part);
96+
}
97+
Console.WriteLine("==============================");
98+
}
99+
100+
}
Lines changed: 23 additions & 0 deletions
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+
"Builder/1.0.0": {
10+
"runtime": {
11+
"Builder.dll": {}
12+
}
13+
}
14+
}
15+
},
16+
"libraries": {
17+
"Builder/1.0.0": {
18+
"type": "project",
19+
"serviceable": false,
20+
"sha512": ""
21+
}
22+
}
23+
}

Builder/bin/Debug/net6.0/Builder.dll

6.5 KB
Binary file not shown.

Builder/bin/Debug/net6.0/Builder.exe

146 KB
Binary file not shown.

Builder/bin/Debug/net6.0/Builder.pdb

10.8 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
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.
Lines changed: 65 additions & 0 deletions
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\\Builder\\Builder.csproj": {}
5+
},
6+
"projects": {
7+
"C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Builder\\Builder.csproj": {
8+
"version": "1.0.0",
9+
"restore": {
10+
"projectUniqueName": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Builder\\Builder.csproj",
11+
"projectName": "Builder",
12+
"projectPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Builder\\Builder.csproj",
13+
"packagesPath": "C:\\Users\\EdenP\\.nuget\\packages\\",
14+
"outputPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Builder\\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.101\\RuntimeIdentifierGraph.json"
61+
}
62+
}
63+
}
64+
}
65+
}
Lines changed: 16 additions & 0 deletions
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>

0 commit comments

Comments
 (0)