Skip to end of metadata
Go to start of metadata

What is Prototype

You have instantiated an object, called some operations. Your object is now in a state from which you wish to copy itself. In other words, you want to clone the object. This wont be achieved if you just assign the object reference to another variable declared with the similar type as these are object references not the actual data. So, What you need to do is instantiate a new object and copy all the attributes.

To achieve the prototype, you need to wrap the logic of instantiating the object and copying the attributes in a method. Client who needs to have a clone, will call the prototype’s clone method.

Design Time Consideration

You need to consider these points while achieving Prototype:

  • Create an Abstract Super Class with an abstract method CLONE( )
  • Implement the method CLONE( ) in the inherited concrete class
    • Instantiate the object
    • Set all the attributes using own attributes

More information