-
Book Overview & Buying
-
Table Of Contents
Practical Design Patterns for Java Developers
By :
The prototype pattern solves the difficulty of creating new instances of an object with complicated instantiation process, which is too cumbersome and undesirable because it can lead to unnecessary subclassing. The prototype is a very common design pattern and was described in the GoF’s book.
The prototype design pattern becomes very useful when heavy objects need to be created and factories are an unwanted approach. The newly created instance is cloned from its parent because the parent acts as a prototype. Instances are independent of each other and can be customized. Instance logic is not exposed to, and cannot be contributed to by, the client.
There are many examples of using prototype patterns across JDK packages. The Collection framework members implement the clone method required by the inherited Cloneable interface. For example, an ArrayList.clone() method execution creates a shallow...