Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motivation for Clone Objects [closed]

Tags:

c#

clone

When to use Clone (not the definition please)? I can initiate an object and use the object so why to use clone in the real world?

What is the motivation for shallow clone (I know that it copies the value types and make a reference to the the reference type) ?

please give me an examples from the real world and not the definition of clone,deep clone or shallow clone.

thanks in advance.

like image 266
mongo Avatar asked Nov 04 '13 06:11

mongo


2 Answers

please give me an examples from the real world

If you have an object that's not thread safe but you can clone it to multiple independent instances you can then use those individual instances on different threads.

like image 83
ta.speot.is Avatar answered Sep 21 '22 23:09

ta.speot.is


please give me an examples from the real world

One Example which I used some days ago:

I developed a component for printing different kind of documents based on a third party component.

In my context this is a complex construction and not "cheap" and "easy" to instantiate. Sometimes I need more than one printing-component. So use a shallow clone and only replace the config-object ("sub-objects" of printing-component which provides all printing relevant environment informations) gives me what I need with lees amount of work.

like image 44
Micha Avatar answered Sep 25 '22 23:09

Micha