Best practice, copy object, using a shadow Object for a undo functionality

T

Tomas

Hi,

I am a VB.NET newbie that would like to know the best practise when
working with objects and undo user changes to objects properties.

Problem
The system allows the user to change properties of an object; the
system then does some time consuming calculation and provide a solution
to the user. If the user found the solution unsatisfactory, he/she
could either continue making more changes or undo all changes done
since the previous calculation.

Idea
We were thinking of working with two objects, a shadow object that the
user can go back to and the object that is involved in the calculation.
Now and then in code copy the object with its properties to the shadow
object.

Is this sensible way, does VB.NET have anything to facilitate this, are
there any good alternatives?

I appreciate any comments regarding this dilemma,

Tomas Nordlander
 
R

rowe_newsgroups

I would track two variable for each property like so:

Private m_MyProperty as string
Private m_MyPropertyDefault as string

Public Property MyProperty() as String
Get
Return m_MyProperty
End Get
Set (value as string)
m_MyProperty = value
End Set
End Property

Then just set the value of m_MyPropertyDefault to whatever the default
needs to be. Then after the calculations, if the user continues to make
changes just save the new Defaults. Or if the user wants to rollback to
the last defaults call a sub like the following:

Private Sub Rollback()
MyProperty = m_MyPropertyDefualt
' Continue to reset any other properties here
End Sub

Does that make sense?

Thanks,

Seth Rowe
 
T

Tomas

Thanks Seth, it make sense.

Tomas :)

rowe_newsgroups said:
I would track two variable for each property like so:

Private m_MyProperty as string
Private m_MyPropertyDefault as string

Public Property MyProperty() as String
Get
Return m_MyProperty
End Get
Set (value as string)
m_MyProperty = value
End Set
End Property

Then just set the value of m_MyPropertyDefault to whatever the default
needs to be. Then after the calculations, if the user continues to make
changes just save the new Defaults. Or if the user wants to rollback to
the last defaults call a sub like the following:

Private Sub Rollback()
MyProperty = m_MyPropertyDefualt
' Continue to reset any other properties here
End Sub

Does that make sense?

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top