I just learned prototype design Pattern.
I am a Java guy so obviously I learned Java Implementation. but i have some confusion about the Example implementation from the different source.
I think these examples might be wrong
Prototype Using new
Prototype Using new
above examples using new keyword in their clone method implementation.
the following example is good as it is exactly implements stated in Prototype definitions.
Now, my questions are,
- why the above two examples uses new keyword ?
- IF we use new keyword then do not the benefits of this pattern vanished ?
- If i am wrong about above 2 examples than please mention the reasons in your answer .
- and finally , which is the correct implementation ? why ?
Updates 28-06-2013
thanks for all for their answers and comments.though some of them still did not understand what was asked here .
the above all works is a preface to actual problem , what i h =ave been trying to solve is I have a Cache object which contains 30K entries in it in the order of they entered. Now in the UI i have to display this data in ascending or descending order based on the user choice. I can only work on Cache object itself so thought that why not clone given cache object using the prototype pattern and then re arrange the contents of cloned cache object by the user choice and display to them ?
Did i make the correct decision ? I am not the enemy of new operator but do it not be very expensive in this specific case. ?
Note
neither loading of data into cache is not in my hand nor any UI side data manipulation.
what i can do is only manipulate the prefilled cached data .
Thanks Mihir