
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
206
|
Chapter 3: Classes and Structures
NEW
State: 67
Id: foo
ClsName: bar
NEW1
State: 671
Id: foo1
ClsName: bar1
NEW2
State: 672
Id: foo2
ClsName: bar2
NEW3
State: 673
Id: foo3
ClsName: bar3
ROLLBACK(3)
State: 672
Id: foo2
ClsName: bar2
ROLLBACK(2)
State: 671
Id: foo1
ClsName: bar1
ROLLBACK(1)
State: 67
Id: foo
ClsName: bar
ROLLBACK(0)
State: 1
Id: ID1001
ClsName: SomeDataOriginator
This code creates a SomeDataOriginator object and changes its state several times. At
every state change, a new
Memento object is created to save the SomeDataOriginator
object’s state at that point in time. At the end of this code, a for loop iterates over
each
Memento object stored in the MultiMementoCareTaker<SomeDataOriginator.
Memento>
object, from the most recent to the earliest. On each iteration of this loop,
the
Memento object is used to restore the state of the SomeDataOriginator object.
3.31 Disposing of Unmanaged Resources
Problem
Your class references unmanaged resources such as some type of handle or manipu-
lates a block of memory or a file via P/Invoke methods or uses a COM object that