Roadmap › Design Patterns (GoF + Enterprise) in C# › Module: Creational Patterns
Lessons in this course (18)

5. Prototype

IntermediateLowLesson 5 of 18

Create new objects by cloning an existing one.

csharp
public record ReportTemplate(string Title, string Font, IReadOnlyList<string> Columns);
var monthly = new ReportTemplate("Monthly", "Segoe UI", ["Date", "Sales"]);
var weekly = monthly with { Title = "Weekly" };     // records give shallow cloning via 'with'

Watch out for shallow vs deep copy: MemberwiseClone() and with copy references to nested objects.