What is the need for Prototype Pattern
in C# (C Sharp)?

In your web application, if you want to postpone execution of actual class by substituting another class for it then you can do it using Prototype Pattern. The substituted class is the prototype class. The actual class will be a cloned copy of the prototype class. After cloning, you can add more details to your actual class.


Here is a code sample to demonstrate it:

abstract class prototypeClass {
private int member;
public prototypeClass(int member) {
this.member = member;
}
public void getMember() {
Console.WriteLine(“Member value = {0}”, member);
}
public abstract prototypeClass clonePrototype();
}
class actualClass : prototypeClass {
public actualClass(int member):base(member) { }
public override prototypeClass clonePrototype() {
prototypeClass obj = (prototypeClass) this.MemberwiseClone();
return obj;
}

}
class testClass {
actualClass sampleObj = new actualClass(10);
actualClass clonedObj = (actualClass) sampleObj.clonePrototype();
clonedObj.getMember();
}

_______________________________________________________________________

Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource

| What is the need for Bridge Pattern in C#? | What is the need for Builder Pattern in C#? | What is the need for Chain of Responsibility Pattern in C#? | What is the need for Command Pattern in C#? | What is the need for Composite Pattern in C#? | What is the need for Decorator Pattern in C#? | What is the need for Flyweight Pattern in C#? | What is the need for Interpreter Pattern in C#? | What is the need for Iterator Pattern in C#? | What is the need for Mediator Pattern in C#? | What is the need for Memento Pattern in C#? | What is the need for Prototype Pattern in C#? | What is the need for State Pattern in C#? | What is the need for Strategy Pattern in C#? | What is the need for Template Method Pattern in C#? | What is the need for unsafe code in C#? | What is the purpose of assert() in C#? | What is the purpose of AutoResetEvent in .NET? | What is the purpose of Console.ReadLine() in C#? | What is the purpose of machine.config file in .NET? |


| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2017 - All Rights Reserved.