OO business class vs data class..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brad Pears

    #1

    OO business class vs data class..

    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
    "clsContrac t" as follows

    public sub btmSave_click (bunch of aprameters)
    ' Save the Contract data
    dim oCB as new clsContract
    ' Set class properites
    oCB.ContractNo = me.txtContractN o.text
    oCB.CustID = me.txtCustID.te xt
    ' 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_Dat a
    ' Set data class property then update
    oCD.CustID = me.CustID
    oCD.update(sCon tractNo)
    ' Clean up
    oCD = nothing
    end sub

    public class clsContract_Dat a
    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(sContrac tNo 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






  • Mr. Arnold

    #2
    Re: OO business class vs data class..


    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.Sav e (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.Sav e(), you would do this.

    Dim daoc as new daoContract

    daoc.Save(busCo ntract)

    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).



    Comment

    • Spam Catcher

      #3
      Re: OO business class vs data class..

      "Brad Pears" <bradp@truenort hloghomes.comwr ote in
      news:OCKvVSZxHH A.4088@TK2MSFTN GP04.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.

      Comment

      • Brad Pears

        #4
        Re: OO business class vs data class..

        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" <spamhoneypot@r ogers.comwrote in message
        news:Xns996DB28 7C12E8usenethon eypotrogers@127 .0.0.1...
        "Brad Pears" <bradp@truenort hloghomes.comwr ote in
        news:OCKvVSZxHH A.4088@TK2MSFTN GP04.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.


        Comment

        • Mr. Arnold

          #5
          Re: OO business class vs data class..


          "Brad Pears" <bradp@truenort hloghomes.comwr ote in message
          news:eKu2hl8xHH A.5024@TK2MSFTN GP05.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.


          Comment

          • Pritcham

            #6
            Re: OO business class vs data class..

            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

            Comment

            Working...