Skip to content

Commit 265dedd

Browse files
committed
Use a more realistic example to demonstrate prototype
1 parent 158d910 commit 265dedd

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

src/CreationalPatterns/Prototype/PrototypeLibrary/DeepCloneExample/DeepCloneExecutor.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ public static void Execute()
99
{
1010
ConsoleExtension.WriteSeparator("Deep clone example");
1111

12-
var developer = new Developer
12+
var phone = new MobilePhone
1313
{
14-
Name = "John Doe",
15-
Project = new Project
14+
Manufacturer = "Xiaomi",
15+
Model = "11T",
16+
OperatingSystem = new OperatingSystem
1617
{
17-
Name = "File storage service",
18-
Description = "Complex project",
18+
Name = "Android",
19+
Version = "11",
20+
Description = "Android is a mobile OS based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. ",
1921
},
2022
};
2123

22-
var clonedDeveloper = developer.Clone();
23-
clonedDeveloper.Project.Name = "Web crawler";
24+
var clonedPhone = phone.Clone();
25+
clonedPhone.Model = "11T Pro";
2426

25-
developer.PrintDetails();
26-
clonedDeveloper.PrintDetails();
27+
phone.PrintDetails();
28+
clonedPhone.PrintDetails();
2729
}
2830
}
2931
}

src/CreationalPatterns/Prototype/PrototypeLibrary/DeepCloneExample/Models/Developer.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using PrototypeLibrary.DeepCloneExample.Extensions;
3+
4+
namespace PrototypeLibrary.DeepCloneExample.Models
5+
{
6+
public class MobilePhone
7+
{
8+
public string Manufacturer { get; set; }
9+
public string Model { get; set; }
10+
public OperatingSystem OperatingSystem { get; set; }
11+
12+
public void PrintDetails()
13+
{
14+
Console.WriteLine(
15+
$"\nManufacturer: {Manufacturer}" +
16+
$"\nModel: {Model}" +
17+
$"\nOperating system: {OperatingSystem.Name}" +
18+
$"\nOS version: {OperatingSystem.Version}" +
19+
$"\nOS description: {OperatingSystem.Description}");
20+
}
21+
22+
public MobilePhone Clone()
23+
{
24+
return this.DeepClone();
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace PrototypeLibrary.DeepCloneExample.Models
22
{
3-
public class Project
3+
public class OperatingSystem
44
{
55
public string Name { get; set; }
6-
6+
public string Version { get; set; }
77
public string Description { get; set; }
88
}
99
}

0 commit comments

Comments
 (0)