Solved

C# momentos for object serialization?

Posted on 2004-08-16
4
255 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Tom 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:Tom 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

615 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