By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,964 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,964 IT Pros & Developers. It's quick & easy.

OO business class vs data class..

P: n/a
Hi guys!!! Thanks for all your input on previous OO posts. I know it will
be all the same people responding again and I really appreciate your insight
etc.. as you all appear to know what you are doing - each having your own
flare but that is what makes us individuals right?? Anyway, here is a quick
question... (or maybe not so quick)

In my business "Contract" class I have many properties.
When I set these "contract" properties in the GUI layer front end (i.e
populating the Contract business class) when the 'Save' button is clicked, I
want to pass the values to the "data" class for update/insert etc...

Do I create the same "properties" on the data class as I have on the
business class and populate the data class from the properties of the
business class? OR should I pass all the variables as a parameter list
from teh business class to the method I am invoking on the data class to do
the update/insert etc .. ?

I guess the biggest question is should data classes use the same
properties - as in the associated business class(s)? What is the best way to
get the data from teh business class to the data class?

I have been doing the following... (used only 2 properties for demonstration
sake)

The front end would set and call the update method on the business class
"clsContract" as follows

public sub btmSave_click (bunch of aprameters)
' Save the Contract data
dim oCB as new clsContract
' Set class properites
oCB.ContractNo = me.txtContractNo.text
oCB.CustID = me.txtCustID.text
' Call update method to update/insert the data
oCB.Update(oCB.ContractNo)
' clean up
oCB = nothing
end sub

public class clsContract
private sContractNo as string
private iCustID as integer
public property ContractNo as string
get
return sContractNo
end get
set (byval value as string)
sContractNo = value
end set

public property CustID as integer
get
return iCustID
end get
set (byval value as integer)
iCustID = value
end set

public sub new
mybase.new
...some code
end sub

Public sub Update(byval sContractNo as string)
' Call dataclass update method
dim oCD as new clsContract_Data
' Set data class property then update
oCD.CustID = me.CustID
oCD.update(sContractNo)
' Clean up
oCD = nothing
end sub

public class clsContract_Data
private sContractNo as string
private iCustID as integer
public property ContractNo as string
get
return sContractNo
end get
set (byval value as string)
sContractNo = value
end set

public property CustID as integer
get
return iCustID
end get
set (byval value as integer)
iCustID = value
end set

public sub new(sContractNo as string)
mybase.new
me.ContractNo = sContractNo
end sub

Public sub Update(sContractNo as string)
' Call stored procedure to do updatemethod
dim bRet as boolean = false
' Call stored procedure with appropriate parameters
bRet is RunSP("spname", me.ContractNo, me.CustID)
if not bret then
msgbox("Error")
endif
return bret
end sub


Thanks, Brad


Jul 13 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a

Do I create the same "properties" on the data class as I have on the
business class and populate the data class from the properties of the
business class? OR should I pass all the variables as a parameter list
from teh business class to the method I am invoking on the data class to
do the update/insert etc .. ?
Here is where OO comes into play.

You have busContact and it should have all of its data accessor properties.

At the UI, you have busContract.Save (note: I don't know why you're trying
to pass the ContractNo in the Save, as it should have been already populated
in the
busContract (the object).

Then at busContract.Save(), you would do this.

Dim daoc as new daoContract

daoc.Save(busContract)

Then at the daoc.Save() will actually be this within daoContract

Public sub Save(byval obj as busContract)

Then you have reference to obj.ContractNo or the properties in the
busContract (the object) you have passed to the DAL object so that DAL
Object can save the data from the Business Object.

You have reference to obj.ContractNo and all other properties in the
busContract, because the (object) was passed.

I hope you understand this and you need to read some books and see the
examples or code execution if you run a sample project from a book that was
mentioned. :)

You should throw everything out the door that you have learned previously
and start fresh.

I have been programming professionally since 1980 and started on the MS
platform in 1996. Something's I kept over the years and a lot of things I
tossed and started fresh, a blank sheet OO or OOp(s).

Jul 13 '07 #2

P: n/a
"Brad Pears" <br***@truenorthloghomes.comwrote in
news:OC**************@TK2MSFTNGP04.phx.gbl:
I actually have a db table with one record in it that contains the
next contract number to be used among other system default values. I
have a small class
specifically set up to go get default values, increment the next
number etc... So on a new contract, I use this class to get the next
contract number and then I set it on the bus object...
Here's a question - how do you ensure that you won't have any concurrency
issues.

Just make sure that the code you're using to update the contract record is
wrapped in some sort of transaction. Or ensure that the your call is using
the proper synchronization mechanism - i.e. Mutexes to ensure multiple
threads won't be incrementing the same value under laod.
Jul 14 '07 #3

P: n/a
Yes, in the stored procedure that updates this single system 'row' I have it
inside a transaction which either commits or does a rollback. I then check
for the return value in my application and
display an error message if unsuccessful (among other things). In this
particular application, the
chances of multiple salespeople asking for the next contract number at the
exact same time hence causing a potential consistency issue are quite slim
(not that many contracts are really created) - but none the less possible.

Thanks,
Brad

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Brad Pears" <br***@truenorthloghomes.comwrote in
news:OC**************@TK2MSFTNGP04.phx.gbl:
>I actually have a db table with one record in it that contains the
next contract number to be used among other system default values. I
have a small class
specifically set up to go get default values, increment the next
number etc... So on a new contract, I use this class to get the next
contract number and then I set it on the bus object...

Here's a question - how do you ensure that you won't have any concurrency
issues.

Just make sure that the code you're using to update the contract record is
wrapped in some sort of transaction. Or ensure that the your call is using
the proper synchronization mechanism - i.e. Mutexes to ensure multiple
threads won't be incrementing the same value under laod.


Jul 16 '07 #4

P: n/a

"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:eK**************@TK2MSFTNGP05.phx.gbl...
Yes, in the stored procedure that updates this single system 'row' I have
it
inside a transaction which either commits or does a rollback. I then check
for the return value in my application and
display an error message if unsuccessful (among other things). In this
particular application, the
chances of multiple salespeople asking for the next contract number at the
exact same time hence causing a potential consistency issue are quite slim
(not that many contracts are really created) - but none the less possible.
Oracle works the same way in auto increment number to be used on a record as
a primary key. It's not a table with a field, but it's along the same
principles, where the next sequential number is gotten and applied to a
table's primary key.

I thought it was strange at first because of how MS SQL Server does it
normally with it's auto generate number for a table's record key, but it
works.
Jul 16 '07 #5

P: n/a
Hi

Don't know whether you're still looking for an OO intro type book but
I have heard very good reviews of a book called "Doing Objects in
Visual Basic 2005" - by Deborah Kurata - might be worth a look for you

Cheers
Martin

Jul 21 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.