Memento Pattern Code Review
Define the Memento Object
Code Download
- Download Description:memento pattern download
- .NET Framework:3.5
- .NET Language:C#
- Date Published:2009-07-01
- Download Size:11 KB
Code Review
- Memento Pattern Code Review: Define the Memento Object
- Memento Pattern Code Review: Define the Game, Caretaker and Simulator Objects
- Memento Pattern Code Review: Use the Memento Pattern
Code Walkthrough
Define the Memento class (object) which is responsible for implementing the functionality to save and restore application state.
[Serializable]
class Memento
{
MemoryStream m_stream = new MemoryStream();
BinaryFormatter m_formatter = new BinaryFormatter();
public Object Restore() { this.m_stream.Seek(0, SeekOrigin.Begin); Object o = this.m_formatter.Deserialize(this.m_stream); this.m_stream.Close(); return (o); } public Memento Save(Object o) { this.m_formatter.Serialize(this.m_stream, o); return this; } }
public Object Restore() { this.m_stream.Seek(0, SeekOrigin.Begin); Object o = this.m_formatter.Deserialize(this.m_stream); this.m_stream.Close(); return (o); } public Memento Save(Object o) { this.m_formatter.Serialize(this.m_stream, o); return this; } }
The application data is saved (serialized) into a binary format.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!