Prototype Design pattern

Prototype design pattern comes under creational design pattern. This pattern is very easy to understand.

Prototype design pattern provides duplication of an existing object. This can be achieved with Object class clone method. Object creation with new operator is time consuming and costly in an Enterprise projects. So instead of creating object with new operator (which is costly in creation of an object), create object with clone.

Steps to implement Prototype design pattern:

1)  Create an abstract class with clone method

2)  Create concrete classes extending Subscriber abstract class.

 

3) Create a class to get the cloned objects

4) PrototypeDemo uses the SubscriberCache to get the cloned objects of Subscriber.

 Output:

 

Posted in designpatterns and tagged , .

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="">