Intent

Cloning an object by reducing the cost of creation.

Where to use & benefits

Structure


Participants

Prototype  (java.lang.Cloneable)
declares an interface for cloning itself

ConcretePrototype  (RectangleShape, CircleShape, TriangleShape)
implements an operation for cloning itself

Client  (MainApplet)
creates a new object by asking a prototype to clone itself

Example

In the demonstration application, the shape (Rectangle, Trinagle, Circle) objects implements the Cloneable interface to provide the facility to clone the object and the MainApplet class uses the facility to clone already created shape object.

Class Diagram


Source Code Links