DELAPARRA
Index
Color
NL
Category: Design patterns

Prototype

Explained by Updated

What is Prototype?

Prototype: Create new objects by copying (cloning) an existing object instead of constructing from scratch. The Prototype pattern creates new objects by copying an existing one, rather than building them from scratch. You keep a prepared example and clone it whenever you need another, then adjust what is different. This helps when creating an object is expensive or involves many settings. A document template with default styles, a game unit with standard stats or a preconfigured report definition can all serve as prototypes.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Prototype

What should you keep in mind with Prototype?

In PHP, you use clone, and the __clone() method lets you decide how nested objects are copied. Make sure deep copies are made where needed, or the clones will share data with the original and with each other. In many cases, a factory method or a builder with sensible defaults achieves the same result in a way that is easier to read.

At a glance

CategoryDesign patterns
Explained by
Updated

More Design patterns terms

All terms starting with P

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.