Memento implementation on .NET.

I saw two different implementations of memento on .NET.

One of them is quite simple - the object creates another instance of itself.

Another serializes the object using BinaryFormatter and MemoryStream.

What is the preferred method? Can someone point out the advantages / disadvantages of each approach?


By the way, I’m interested in looking at this in terms of resource utilization and developer productivity. I apologize for not specifying this in the first place.

Assuming memory doesn't need to be stored, which is preferable?

In terms of developer productivity, serialization wins hands. A few lines that are universal for any object are more efficient than having to manually create a clone, which includes, possibly, private constructors, field assignments, etc.

But then again, maybe serialization is hard - I'm not sure.

+3
source share
4 answers

, , / , , , , . , . , . , ( ).

+2

,

0

, StringBuilder .

0

BinaryFormatter MemoryStream , Clone() , .

Otherwise, I do not see a match to choose between the two methods if the memory does not need to be saved

0
source

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


All Articles