Re: Object scope issue...
- From: "RobinS" <robins@xxxxxxxxxxxxxxxx>
- Date: Tue, 5 Feb 2008 23:40:23 -0800
How is your business object set up? When you say the user clicks to save a row, are you using a datagridview, or do you mean just to add a new object?
Have you checked out Deborah Kurata's book "Doing Objects in VB2005" ? It talks about how to handle the state of an object, and how to handle updates. Great book.
RobinS.
GoldMail, Inc.
-------------------------------------
"Brad Pears" <bradp@xxxxxxxxxxxxxxxxxxxxx> wrote in message news:OMG8tNEaIHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
I just have a question about how objects should be used in situations where you want to preserve an object's state while performing some particular function.
In my vb.net 2005 app, a user enters data and then clicks a "Save" command
button to save the row. If the user simply changes existing data on the
form, (meaning a row already exists) I only do a database update. However,
if the user was adding a new row I would have first created a new instance
of the object and subsequently added the row data to the database.
I set up the object as a "public" variable in my main vb module like this...
"public MyObj as clsMyObj"
Then in the "Save" command button code, I first check to see if MyObj =
nothing. If so, I then create a new instance of the object (MyObj=new
clsMyObj) and run code that inserts the new row.
If the user were to go back and modify some data and clicks the "Save" command button again, I
would expect my code above (if MyObj = nothing ) to be false and I would
then just update the data as opposed to updating it.
Is this typically how one would control an objects scope - by setting as a public variable and checking to see if
the object = nothing or object = something? If so than does this mean that for any object that I need to preserve scope, I need to setup as a
public variable?
I am new to OO design etc... and I want to make sure that I don't have copies of objects all over the place etc... It seems that there must be a better way to do this?
Help!
Thanks, Brad
.
- Follow-Ups:
- Re: Object scope issue...
- From: Brad Pears
- Re: Object scope issue...
- References:
- Object scope issue...
- From: Brad Pears
- Object scope issue...
- Prev by Date: Re: get Quarter value for specific date (OT)
- Next by Date: Re: Prevent change or edit data using bindingsource
- Previous by thread: Re: Object scope issue...
- Next by thread: Re: Object scope issue...
- Index(es):