The prototype design pattern

The prototype design pattern is a creational design pattern that involves creating objects by cloning them from existing ones. Its purpose is related to performance and keeping it high by trying to avoid expensive calls.

Class diagram

In languages such as Java, we usually see a class that implements an interface with a clone method, which returns a new instance of the class. The following figure shows an example diagram:

Class diagram

In the next section, we will provide a code example of the prototype design pattern from the point of view of Scala.

Code example

The prototype design pattern is really easy to implement in Scala. We can ...

Get Scala Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.