Skip to main content

Posts

Showing posts with the label prototype

Creational Patterns : Prototype

Properties: -            When cost of creating an object from scracth is high it might be good idea to create it by cloning an existing object. -            Identified by a super class declaring a clone method and implemented clone method inside class. Implementation: -            Class extends a super class which declares a clone method. -            Clone method is implemented to create a copy of the object. Java Standard Library Implementations: -            Any class implementing  java.lang.Cloneable Example Usage: // simply person clone is invoked Person newPerson  =   ( Person ) person . clone ();