Summer SALE
Prototype

in Swift

is a creational design pattern that allows cloning objects, even complex ones, without coupling to their specific classes.

All classes should have a common interface that makes it possible to copy objects even if their concrete classes are unknown. objects can produce full copies since objects of the same class can access each other’s private fields.

Complexity:

Popularity:

Usage examples: The pattern is available in Swift out of the box with a NSCopying interface.

Identification: The can be easily recognized by a clone or copy methods, etc.

The following examples are available on Swift Playgrounds.
Kudos to Alejandro Mohamad for creating the Playground version.

in Other Languages

Prototype in C#Prototype in C++Prototype in GoPrototype in JavaPrototype in PHPPrototype in PythonPrototype in RubyPrototype in RustPrototype in TypeScript