Prototype Pattern

Prototype pattern implements a prototype interface which tells to create a clone of the current object. This pattern is used when creation of object directly is costly.

The Prototype pattern allows an object to create customized objects without knowing their class or any details of how to create them. The difference between Factory method and Prototype pattern is that Prototype doesn’t require subclassing, but it does require an “initialize” operation. Factory Method requires subclassing, but doesn’t require Initialize.


Prototype pattern

Step 1
create an abstract class TrackingAgent which will implement Cloneable interface

Step 2
create TrackingAgent subclasses FedexTrackingAgent, DhlTrackingAgent and UpsTrackingAgent

Step 3
Create a map or hashtable to save a instance of each tracking agent

Step 4
Write a client to demo how to get a clone copy that was saved in the AgentAche


Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

2 thoughts on “Prototype Pattern

  1. Pingback: Software Design Patterns

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">