Prototype Design Pattern

Prototype Design Pattern: This pattern is used when objects or instances are created by cloning other object or instances. It allows to add any sub class instance of known super class instance. It is used when there are numerous potential classes , that are ready to use when needed.

It falls under creational design pattern.

Example: C0de is also available at GitHub. Click here to go to git hub repository.

namespace PrototypeDesignPattern

{

class Program

{

static void Main(string[] args)

{

Cat cat = new Cat();

Cat cloneCat = (Cat)cat.CLone();

 

Dog dog = new Dog();

 

Dog cloneDog = (Dog)dog.CLone();

 

Console.ReadLine();

}

}

 

public interface Animal

{

Animal CLone();

}

public class Cat : Animal

{

public Animal CLone()

{

Cat cat = null;

cat = (Cat) this.MemberwiseClone();

return cat;

}

}

public class  Dog:Animal

{

public Animal CLone()

{

Dog dog = null;

dog = (Dog)this.MemberwiseClone();

return dog;

}

}

}

Author: Rupesh

Hi! I'm Rupesh, a funophile and technophile. I'm an Application Developer, Solution Architect and IT-Consultant, and an author in the works. I am a Microsoft certified Professional and Solution Developer (MCP and MCSD).

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s