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.
source
share