Design Pattern (Part 03)— Prototype Design Pattern!

Advantage of Prototype Pattern

UML for Prototype Pattern

Prototype Design Pattern Implementation

  1. Create a Product class that implements the cloneable interface. List all the parameters and create a setter getter for them. Create appropriate constructors.
  2. If parameters contain all immutable fields, there is no need to override the clone() method.
  3. If any parameter is mutable, We need to override the clone() method and write appropriate deep cloning logic.
  4. The clone method will return a new object of the Product class with all field values as per the original product object.

Real-world Example



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arun prashanth

Arun prashanth

Software Engineer at Virtusa (Pvt) Ltd.