Creates objects by cloning an existing object
Application need to know the class of objects already created to create more using new.
Let objects to create others from themselves using a clone method.
Create a factory object to maintain the initial instances
- Prototype can avoid expensive "creation from scratch"
- Let client to create objects without know the type
- Rules for method clone in JVM:
- x.clone() != x will be true
- x.clone().getClass() == x.getClass() will be true, but these are not absolute requirements.
- x.clone().equals(x) will be true, this is not an absolute requirement.
- Singleton avoids the creation of multiple instances. Prototype return a new instance in every call.
- Factory method: creation through inheritance. Prototype: creation through delegation