Solved

C# momentos for object serialization?

Posted on 2004-08-16
4
248 Views
Last Modified: 2008-03-10
I've been reading a book on C#.

When it talks about struct  (value type)  vs   class (reference type) it says:

"structs are best used for simple data types or momentos for object serialization and object state."

I don't understand the usage of "momentos" here, nor do I understand object serialization and object state.

Can someone enlighten me?
0
Comment
Question by:knowlton
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11814724
knowlton this explains the pattern which .net uses for serialization oddly enough named the momento pattern and explains what exactly a momento is http://www.ondotnet.com/pub/a/dotnet/2002/09/09/memento.html
0
 
LVL 5

Author Comment

by:knowlton
ID: 11815429
Greg:

Perfect!

Any anecdotes you can provide me regarding actual usage (by you)?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11815538
my guidelines have always been ...

1) you want deep copy behavior implicitly (valye type)
2) you are using many times over in a local context example
3) when you are not copying it around a whole bunch
4) when you are not boxing/unboxing

as for using a momento ...

lets say I have a form ... (btw this is a PERFECT example) ...

lets say it has 30 fields on it that are adjustable by the user control locations etc ...

I cannot serializae the form for various reasons

What I do is implement ISerializable and serialize out an object that contains the 30 fields ... then on deserialization I use those 30 fields to set the value (the object itself only existed for a moment ... just to copy (hence a momento))

Another reason why the above is a great example is that in order to really serialize the form I would need to serialize hundreds, maybe thousands of values when in actuality I only needed 30 as the rest will come up programatically, thus I have reduced my serialization size.

0
 
LVL 5

Author Comment

by:knowlton
ID: 11816163
Cool.

This is way over my head right now....but I'm glad to see there are some practical applications to this concept.

Tom
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XAML: Layout 8 25
Runtime Error 2 28
How would you add MULTITHREADING to the attached C# code? 4 52
Web Form VB.Net  import CSV 4 27
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now