- if objects are available,copy and use them instead of creating new ones
- clone the available object,modify and use
- modify clone method to create new objects,such that cloning will provide the necessary object
- used if we need many instances which are having little differences
- can use shallow or deep copy
- the object which we copy must provide the copying feature
- cloning isles expensive that creating objects using new operator
- Use
- when the classes to instantiate are specified at runtime
- When instances of a class can have one of only a few different combinations of state
- JDK
- java.lang.Object#clone() (the class has to implement java.lang.Cloneable)
- Example: will update !
Reference :HowToDoInJava , Javapapers, A good read,