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

+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>

Builder/Program.cs

+100
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+
}
+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+
"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.
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.
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+
}
+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>
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("Builder")]
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("Builder")]
18+
[assembly: System.Reflection.AssemblyTitleAttribute("Builder")]
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+
d22192c8f1be8d700b0fe15bc8d5e4b7a09426b7
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 = Builder
10+
build_property.ProjectDir = C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\
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+
8d3a3d9868eede34ab68e656db9928da5960d2e1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.csproj.AssemblyReference.cache
2+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.GeneratedMSBuildEditorConfig.editorconfig
3+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.AssemblyInfoInputs.cache
4+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.AssemblyInfo.cs
5+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.csproj.CoreCompileInputs.cache
6+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\bin\Debug\net6.0\Builder.exe
7+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\bin\Debug\net6.0\Builder.deps.json
8+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\bin\Debug\net6.0\Builder.runtimeconfig.json
9+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\bin\Debug\net6.0\Builder.dll
10+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\bin\Debug\net6.0\ref\Builder.dll
11+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\bin\Debug\net6.0\Builder.pdb
12+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.dll
13+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\ref\Builder.dll
14+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.pdb
15+
C:\Users\EdenP\Desktop\Projects\DesignPattern\Builder\obj\Debug\net6.0\Builder.genruntimeconfig.cache

Builder/obj/Debug/net6.0/Builder.dll

6.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
940321c11984112b6de10daf18757aa7cd5a397b

Builder/obj/Debug/net6.0/Builder.pdb

10.8 KB
Binary file not shown.

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

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

Builder/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\\Builder\\Builder.csproj",
18+
"projectName": "Builder",
19+
"projectPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Builder\\Builder.csproj",
20+
"packagesPath": "C:\\Users\\EdenP\\.nuget\\packages\\",
21+
"outputPath": "C:\\Users\\EdenP\\Desktop\\Projects\\DesignPattern\\Builder\\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.101\\RuntimeIdentifierGraph.json"
68+
}
69+
}
70+
}
71+
}

Builder/obj/project.nuget.cache

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

0 commit comments

Comments
 (0)