Skip to content
Veltoryx Technologies
ProLesson 4.5Intermediate7 min readUpdated 31 October 2026

Prototype Pattern

Learn how to create new objects by copying an existing one, the crucial difference between shallow and deep copies, and why Java developers prefer copy constructors to clone().

When you need ten copies of a filled-in form, you do not fill it in ten times. You fill it in once, put it in a photocopier and press a button. If you need slightly different versions, you copy the form and change a name or a date on each copy. The original is the prototype, and every new form starts as a copy of it.

The Prototype pattern brings this idea to code: instead of building every new object from scratch, you copy an existing object and adjust what is different. It is the last of the five creational patterns in this module, and the one where one detail, shallow versus deep copying, causes the most bugs.

01The problem

Imagine a game that needs hundreds of enemies. A "goblin" enemy takes a long time to create, because its constructor loads a 3D model, reads sound files and calculates its attack tables. If the game builds each goblin from scratch, the screen freezes every time a wave of enemies appears.

Another situation: your program has many objects that differ only slightly. A company has 50 report templates, each a copy of a standard template with a few changed fields. Building each from nothing means repeating the same setup 50 times.

A third situation: you hold an object only through an interface (Shape shape) and you want a copy of it, but you do not know its concrete class. You cannot write new Circle(...), because you do not know it is a circle.

In all three cases, the natural answer is: make a copy of the thing you already have.

Loading the rest of the lesson…