Prototype Pattern

Definition

Cloning an object by reducing the cost of creation.

Where to use & benefits

  • When there are many subclasses that differ only in the kind of objects,
  • A system needs independent of how its objects are created, composed, and represented.
  • Dynamic binding or loading a method.
  • Use one instance to finish job just by changing its state or parameters.
  • Add and remove objects at runtime.
  • Specify new objects by changing its structure.
  • Configure an application with classes dynamically.

The prototype pattern is a creational design pattern. In the prototype pattern, a new object is created by cloning an existing object. In JavaSW, the clone() method is an implementation of this design pattern. The prototype pattern can be a useful way of creating copies of objects. One example of how this can be useful is if an original object is created with a resource such as a data stream that may not be available at the time that a clone of the object is needed. Another example is if the original object creation involves a significant time commitment, such as reading data from a databaseW or over a network. An added benefit of the prototype pattern is that it can reduce class proliferation in a project by avoiding factory proliferation.

 

Advertisements

About Sanju
I am Software Programmer. I am working in JAVA/J2EE Technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: