Exploring the Prototype Design Pattern

Standard Definition

The prototype design pattern is a creational design pattern that allows developers to hide the complexity of making new instances from clients by copying (cloning) an existing object rather than creating a new instance from scratch.

Fig 1: Prototype Design Pattern

Prototype Design Pattern in the Context of Java

Cloneable Interface in Java

Shallow Copy vs the Deep Copy

Shallow Copy

Deep Copy

Keywords

Usage

Prototype Design Pattern in the Context of JavaScript

Case Study

What is the problem with this implementation?

So what we can do?

How to improve?

Further improvement using the Prototype Instantiation Pattern

Sharing methods across all instances of a function with “New” Keyword

Associate Software Engineer at Virtusa