Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 15388 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > .NET Framework Interview Questions > What is the Prototype Design Pattern ? . ...

What is the Prototype Design Pattern ?

Interview question and answer by: Bharathi Cherukuri | Posted on: 4/26/2012 | Category: .NET Framework Interview questions | Views: 882 | | Points: 40
Ads
Ads


Answer:

A prototype design pattern relies on creation of clones rather than objects.
Here, we avoid using the keyword 'new' to prevent overheads.

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


 Responses

Posted by: Rajni.Shekhar | Posted on: 27 Apr 2012 08:08:46 AM | Points: 10 | Alert Moderator 

can you please give some example of prototype design.

Posted by: Bharathi Cherukuri | Posted on: 27 Apr 2012 09:35:24 AM | Points: 10 | Alert Moderator 

Sure Rajini..

Example:

//Note: In this example ICloneable interface (defined in .Net Framework) acts as Prototype

class ConcretePrototype : ICloneable

{
public int X { get; set; }

public ConcretePrototype(int x)
{
this.X = x;
}

public void PrintX()
{
Console.WriteLine("Value :" + X);
}

public object Clone()
{
return this.MemberwiseClone();
}
}

/**
* Client code
*/
public class PrototypeTest
{
public static void Main()
{
var prototype = new ConcretePrototype(1000);

for (int i = 1; i < 10; i++)
{
ConcretePrototype tempotype = prototype.Clone() as ConcretePrototype;

// Usage of values in prototype to derive a new value.
tempotype.X *= i;
tempotype.PrintX();
}
Console.ReadKey();
}
}

/*
**Code output**

Value :1000
Value :2000
Value :3000
Value :4000
Value :5000
Value :6000
Value :7000
Value :8000
Value :9000
*/


Regards,
Bharathi

>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Bharathi Cherukuri

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 6:11:15 PM