Prototype Pattern
The prototype pattern states that a copy ( clone ) of the object is returned rather than creating a brand new object from scratch.
Factory Pattern
Abstract Factory Pattern
This pattern allows us to centralize factory creation classes. The Abstract Factory will give us a factory creation class. It is used in JDK .
javax.xml.parsers.DocumentBuilderFactory.newInstance(String factoryClassName, ClassLoader classLoader)
The above method returns a Factory object based on the name and the class loader we provide to it.
String provider =
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
// create a new DocumentBuilderFactory from an implementation
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance(provider, null);
In the above section we have specified the name in the string variable "provider" . It's quite possible that JDK might provide us with an alternate implementation and we can grab the factory using the related provider name.