Why hasn't Microsoft made a deep clone feature in BCL?

They obviously used it somewhere, why didn't they give such a method? (Even if they did not use it anywhere, they could still give us such a method).

+3
source share
5 answers

Perhaps because the naive implementation of deep cloning is more dangerous than useful . Without special care, you can easily accidentally clone huge chunks of your entire application heap - including things that should not be cloned. In practice, deep cloning is typically implementation-specific — the cloner knows what he is looking for, and only follows these paths.

- , .

+9

; singleton , " " .

+2

( ) , , " " , , . / : , .

, . , , , -, .

+1
source

BinaryFormatter's own behavior is actually a deep clone. There is an IClonable interface with .NET 1.0, but it is deprecated, and MS advises AGAINST to implement this interface, especially because of concerns that the consumer does not necessarily know if the implementation of IClonable implements a deep or shallow clone. Deep cloning is dangerous.

0
source

Because deep cloning is serious enough to warrant multiple namespaces. See Serialization.

0
source

Source: https://habr.com/ru/post/1792635/


All Articles