© Dmitri Nesteruk 2020
D. NesterukDesign Patterns in .NET Core 3https://doi.org/10.1007/978-1-4842-6180-4_5

5. Prototype

Dmitri Nesteruk1  
St. Petersburg, c.St-Petersburg, Russia

Deep vs. Shallow Copying

Suppose we define a class Person as
public class Person
  public readonly string Name;
  public readonly Address Address;
  public Person(string name, Address address) { ... }
with the Address defined as
public class Address
  public readonly string StreetName;
  public int HouseNumber;
  public Address(string streetName, int houseNumber) { ... }
Suppose John Smith and Jane Smith are neighbors. It should be possible to construct John, then just copy him and change the house number, right? Well, using the assignment operator (=) certainly won’t help: ...

Get Design Patterns in .NET Core 3: Reusable Approaches in C# and F# for Object-Oriented Software Design now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.