Home All Groups Group Topic Archive Search About

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

Author
8 Nov 2006 1:57 PM
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

Author
8 Nov 2006 2:39 PM
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


Tomas wrote:
Show quoteHide quote
> 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
Author
8 Nov 2006 4:20 PM
Tomas
Thanks Seth, it make sense.

Tomas :)

rowe_newsgroups wrote:
Show quoteHide quote
> 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
>
>
> Tomas wrote:
> > 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