Click here to Skip to main content
14,329,910 members
Rate this:
Please Sign up or sign in to vote.
See more:
In my project there was a req to clone an employee object. I created a memberwiseclone function with in employee class and implemented clone functionality. Recently i read prototype pattern and i am confused why to implement protoype just to do clone why not simply create a function as i did earlier.

What I have tried:

Implemented prototype and tested.
Posted
Updated 8-Aug-19 10:20am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Here is a good article about it: Prototype .NET Design Pattern in C# and VB - dofactory.com[^]
DZone has an overview and refCard of design patterns: https://dzone.com/refcardz/design-patterns?chapter=1[^]
As replying to your question does not seem to work at the moment: it shows the use of abstract classes.
But don't get the idea that you must use design patterns all the time, it can make simple programs unnecessary complex !
   
v4
Comments
code4Better 8-Aug-19 13:25pm
   
This is the one which i already read. I k ow how to implement but why to implement since simply we can create a function inside class, that was my question
code4Better 8-Aug-19 13:28pm
   
Can you please read my question once again
code4Better 9-Aug-19 0:31am
   
Thanks Rickzeeland.
Rate this:
Please Sign up or sign in to vote.

Solution 2

If you look at the documentation on both

Object.MemberwiseClone Method (System) | Microsoft Docs[^]

Prototype .NET Design Pattern in C# and VB - dofactory.com[^]

you will see that they both perform a shall copy on the object. The latter is a design pattern which will give you an approach to common problems and how to solve them in a cleaner fashion.

BUT as RickZeeland tried to point out, design patterns are useful in the right situation but when used incorrectly they do nothing more than add additional complexity to your project.
   
Comments
code4Better 9-Aug-19 0:32am
   
Thanks Simon

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100