design-patterns

Quick-reference guide to software design patterns with concise Dart examples.

View project on GitHub

Creates new objects by cloning an existing object (the prototype) instead of building from scratch.

Useful when object creation is costly and objects share most of their state.

class Shape {
  String color;
  double x, y;

  Shape(this.color, this.x, this.y);

  Shape clone() => Shape(color, x, y);
}

// Usage
final original = Shape('red', 10, 20);
final copy = original.clone()..color = 'blue';