In general, there are two ways to go about doing what you need:
- Store the state of the object, and
- Store the sequence of commands that lead the object to its current state
The first way is addressed by externalization of an object's state. Essentially, you write to an external storage of some sort a file with a description of the current state of the object:
Label at 40,10 text "Are you sure?"
Button at 40,20 size 30,10 text "OK"
Button at 40,40 size 30,10 text "Cancel"
You can read this file and restore the object to its current state.
The second way is addressed by storing commands, like this:
Add Label id 123 at 0,0
Move id 123 to 40,15
Set text id 123 "Are you crazy?"
Move id 123 to 40,10
Add Button id 124 at 0,0
Set text id 124 "Cancel"
Move id 124 to 40,40
Add Button id 125 at 0,0
Set text id 125 "OK"
Move id 125 to 40,20
Set text id 123 "Are you sure?"
When you have a file like that, you can "replay" it to get the current state of your object. But more importantly, you can use it to implement "undo" that survives exiting the application. If you add timestamps to the events, you would also get a way to restore the state as of some time in the past.