Data/Business Object Tier Best Practices

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

    #16
    Re: Data/Business Object Tier Best Practices



    "Doug Taylor" wrote:
    [color=blue]
    > On Thu, 23 Jun 2005 16:55:01 -0700, "JeremyHolt "
    > <JeremyHolt@dis cussions.micros oft.com> wrote:
    >[color=green]
    > >Hi,
    > >
    > >I have previously written fairly large projects using datasets/dataviews
    > >with good results.
    > >However, ever since having got hold of VB.Net Beta 2, I have been looking at
    > >generics - List(Of type), and been messing around with the class designer.
    > >
    > >I am now starting a new project, where the backend is presently an
    > >antiquated DB2 database running on an AS/400 which may or may not move to SQL
    > >Server, and the UI will be both Windows Forms and Explorer.
    > >
    > >Playing around with the class designer, I have created my model, which is
    > >essentially classes and collections of classes. The designer allows me to
    > >visualise very clearly the interrelationsh ips between the various classes. In
    > >the past, I have always started with the database and built the application
    > >from there on up. Since the prospect of actually getting the data in and out
    > >of the AS/400 is so daunting, I decided to build the middle tier (business
    > >rules) first and then worry about the data access layer.
    > >
    > >However, I have now hit a mental brick wall. I can't see how and where I
    > >will be able to update/insert the back-end data from these classes. I
    > >downloaded the TimeTracker v 2.0 Starter Kit from asp.net, but since I'm not
    > >very goods with C#, haven't been able to really figure out the logic between
    > >the n tiers.
    > >
    > >I'm in a bit of a quandry - I would really like to continue using the class
    > >designer to build the application, but would also like to continue to use
    > >datasets etc because of their ease of use.
    > >
    > >Is there somewhere I can go which will point me in the direction of a hybrid
    > >model - or must I decide now which way I want to go?[/color]
    >
    > Jeremy,
    >
    > You are basically using a model which is known as business objects,
    > i.e. you are putting a layer in place between the Database Layer and
    > the Presentation Layer that understands your business rules. An
    > alternative approach of course is to place these business rules in the
    > database as stored procedures and triggers.
    >
    > There are good reasons for both of these approaches.
    >
    > Your problem is as you say is to tie the business objects to the
    > database, there are two common approaches to this, the first is to
    > have as a private member a typed record in each class and a typed
    > recordset in the collection and use that to interact with the
    > database. The second is to give your objects the ability to access
    > the database directly. Again both approaches are valid. There are a
    > number of articles on the internet that discuss the merits of these
    > approaches.
    >
    > Doug Taylor[color=green]
    > >
    > >Many thanks
    > >Jeremy Holt
    > >[/color]
    >
    >[/color]
    Doug,

    Many thanks for your thoughts on this. I had previoulsy thought about a
    private typed record in the class, but then found myself inserting the data
    into the class properties from the dataset - this seemed rather
    counter-intuituve in that if I already have the typed dataset, why would I
    want to transfer this data back into my "typed" class. I also have a problem
    visualising how one would handle the "collection ".

    In my business model, I have defined the following classes:


    Class Product
    ProductID as integer
    SampleSize as double
    Description as string
    Grade as string
    MoistureContent as double
    Ash as double
    Rotten as double
    End Class

    Class LaboratoryAnaly sis
    LabID as integer
    Date as date
    Products as List(Of Product)
    End Class

    Class Truck
    TruckID as integer
    NumberPlate as string
    Origin as string
    Quantity as integer
    LabAnalysis as List(Of LaboratoryAnaly sis)
    End Class

    Class Warehouse
    WarehouseID as integer
    Trucks as List(Of Truck)
    End Class

    I tend to think in terms of stored procs/triggers filling/updating datasets,
    producing dataviews which are consumed by the UI. Single records (master part
    of master/details) are obtained through passing a parameter to the stored
    proc. As I said in my previous post, I know it works, and its relatively easy
    to do.

    However, I am constantly drawn back to the idea of classes/collection of
    classes, because of the elegance of the Class Designer.

    In my "dataset world" in order to fill my Warehouse I would have a stored
    proc which queried the database and would do an inner join accross the tables
    to give me the "collection " of Trucks - in reality a dataview, which would
    continue to drill down through the LaboratoryAnaly sis to the Products that
    were analysed in the laboratory etc. My query would thus be able to give me
    how many tons of Rotten Apples I have in the Warehouse.

    In my "Generics world" my Business Objects code would be something like:

    Dim TotalWeight as integer
    Dim RottenWeight as double
    For each T as Truck in Warehouse.Truck s
    TotalWeight += T.Quantity
    For each L as LaboratoryAnaly sis IN T.LabAnalysis
    For each P as Product in L.Products
    RottenWeight += (T.Quantity * P.Rotten)
    Next
    Next
    Next

    Assuming I'm along the right lines so far, how would I get the data, and
    update the data into my collections? I guess something like:

    Class Product
    ProductID as integer
    SampleSize as double
    Description as string
    Grade as string
    MoistureContent as double
    Ash as double
    Rotten as double

    Sub Load(ProductID as integer)
    Dim ds as dsProducts
    ' Fill dataset
    'SELECT ProductID, SampleSize, Description, Grade, MoistureContent , Ash,
    Rotten FROM Products WHERE ProductID BETWEEN COALESCE(-1, '@ProductID) AND
    COALESCE(65535, @ProductID)
    For Each row as dsProducts.Prod uctsRow in dsProducts
    Me.SampleSize = row.SampleSize
    Me.Description = row.Description
    etc.
    Next
    End Sub
    End Class

    However, this is where I run into my mental "brick wall":
    1) Should Class Product not just expose the dataset, saving me the effort of
    the loop to fill the class properties with the row details?
    2) How do I update Class Product? Assuming that I'm using a DataGridSource
    (asp.net or win.forms), if the souce of these UI elements is a dataview, then
    I can use all of ADO.Net's capababilities, i.e. Merge, GetChanges(data set)
    etc.

    If I carry on down the road of my "Generics" model do I have to lose all the
    "cool" things about ADO.Net? Alternativley, how do I model my "traditiona l
    database oriented" design using Class Designer?

    I do hope that I have been able to clearly express my confusion, and hope
    that someone could point me in the right direction.

    Many thanks
    Jeremy Holt


    Comment

    • Jeremy Holt

      #17
      Re: Data/Business Object Tier Best Practices

      Cor

      In which forum would you suggest I post?

      Thanks
      Jeremy

      "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
      news:%238G8H4He FHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Jeremy,
      >
      > This can be very interesting to discuss this in these newsgroups.
      >
      > http://forums.microsoft.com/MSDN/default.aspx
      >
      > For those problems you have now is in my opinion beta testing for.
      >
      > Cor
      >
      >
      >[/color]


      Comment

      • Cor Ligthert

        #18
        Re: Data/Business Object Tier Best Practices

        > Cor[color=blue]
        >
        > In which forum would you suggest I post?[/color]





        Comment

        • Doug Taylor

          #19
          Re: Data/Business Object Tier Best Practices

          On Fri, 24 Jun 2005 09:09:06 -0700, "JeremyHolt "
          <JeremyHolt@dis cussions.micros oft.com> wrote:
          [color=blue]
          >
          >
          >"Doug Taylor" wrote:
          >[color=green]
          >> On Thu, 23 Jun 2005 16:55:01 -0700, "JeremyHolt "
          >> <JeremyHolt@dis cussions.micros oft.com> wrote:
          >>[color=darkred]
          >> >Hi,
          >> >
          >> >I have previously written fairly large projects using datasets/dataviews
          >> >with good results.
          >> >However, ever since having got hold of VB.Net Beta 2, I have been looking at
          >> >generics - List(Of type), and been messing around with the class designer.
          >> >
          >> >I am now starting a new project, where the backend is presently an
          >> >antiquated DB2 database running on an AS/400 which may or may not move to SQL
          >> >Server, and the UI will be both Windows Forms and Explorer.
          >> >
          >> >Playing around with the class designer, I have created my model, which is
          >> >essentially classes and collections of classes. The designer allows me to
          >> >visualise very clearly the interrelationsh ips between the various classes. In
          >> >the past, I have always started with the database and built the application
          >> >from there on up. Since the prospect of actually getting the data in and out
          >> >of the AS/400 is so daunting, I decided to build the middle tier (business
          >> >rules) first and then worry about the data access layer.
          >> >
          >> >However, I have now hit a mental brick wall. I can't see how and where I
          >> >will be able to update/insert the back-end data from these classes. I
          >> >downloaded the TimeTracker v 2.0 Starter Kit from asp.net, but since I'm not
          >> >very goods with C#, haven't been able to really figure out the logic between
          >> >the n tiers.
          >> >
          >> >I'm in a bit of a quandry - I would really like to continue using the class
          >> >designer to build the application, but would also like to continue to use
          >> >datasets etc because of their ease of use.
          >> >
          >> >Is there somewhere I can go which will point me in the direction of a hybrid
          >> >model - or must I decide now which way I want to go?[/color]
          >>
          >> Jeremy,
          >>
          >> You are basically using a model which is known as business objects,
          >> i.e. you are putting a layer in place between the Database Layer and
          >> the Presentation Layer that understands your business rules. An
          >> alternative approach of course is to place these business rules in the
          >> database as stored procedures and triggers.
          >>
          >> There are good reasons for both of these approaches.
          >>
          >> Your problem is as you say is to tie the business objects to the
          >> database, there are two common approaches to this, the first is to
          >> have as a private member a typed record in each class and a typed
          >> recordset in the collection and use that to interact with the
          >> database. The second is to give your objects the ability to access
          >> the database directly. Again both approaches are valid. There are a
          >> number of articles on the internet that discuss the merits of these
          >> approaches.
          >>
          >> Doug Taylor[color=darkred]
          >> >
          >> >Many thanks
          >> >Jeremy Holt
          >> >[/color]
          >>
          >>[/color]
          >Doug,
          >
          >Many thanks for your thoughts on this. I had previoulsy thought about a
          >private typed record in the class, but then found myself inserting the data
          >into the class properties from the dataset - this seemed rather
          >counter-intuituve in that if I already have the typed dataset, why would I
          >want to transfer this data back into my "typed" class. I also have a problem
          >visualising how one would handle the "collection ".
          >
          >In my business model, I have defined the following classes:
          >
          >
          >Class Product
          > ProductID as integer
          > SampleSize as double
          > Description as string
          > Grade as string
          > MoistureContent as double
          > Ash as double
          > Rotten as double
          >End Class
          >
          >Class LaboratoryAnaly sis
          > LabID as integer
          > Date as date
          > Products as List(Of Product)
          >End Class
          >
          >Class Truck
          > TruckID as integer
          > NumberPlate as string
          > Origin as string
          > Quantity as integer
          > LabAnalysis as List(Of LaboratoryAnaly sis)
          >End Class
          >
          >Class Warehouse
          > WarehouseID as integer
          > Trucks as List(Of Truck)
          >End Class
          >
          >I tend to think in terms of stored procs/triggers filling/updating datasets,
          >producing dataviews which are consumed by the UI. Single records (master part
          >of master/details) are obtained through passing a parameter to the stored
          >proc. As I said in my previous post, I know it works, and its relatively easy
          >to do.
          >
          >However, I am constantly drawn back to the idea of classes/collection of
          >classes, because of the elegance of the Class Designer.
          >
          >In my "dataset world" in order to fill my Warehouse I would have a stored
          >proc which queried the database and would do an inner join accross the tables
          >to give me the "collection " of Trucks - in reality a dataview, which would
          >continue to drill down through the LaboratoryAnaly sis to the Products that
          >were analysed in the laboratory etc. My query would thus be able to give me
          >how many tons of Rotten Apples I have in the Warehouse.
          >
          >In my "Generics world" my Business Objects code would be something like:
          >
          >Dim TotalWeight as integer
          >Dim RottenWeight as double
          >For each T as Truck in Warehouse.Truck s
          > TotalWeight += T.Quantity
          > For each L as LaboratoryAnaly sis IN T.LabAnalysis
          > For each P as Product in L.Products
          > RottenWeight += (T.Quantity * P.Rotten)
          > Next
          > Next
          >Next
          >
          >Assuming I'm along the right lines so far, how would I get the data, and
          >update the data into my collections? I guess something like:
          >
          >Class Product
          > ProductID as integer
          > SampleSize as double
          > Description as string
          > Grade as string
          > MoistureContent as double
          > Ash as double
          > Rotten as double
          >
          > Sub Load(ProductID as integer)
          > Dim ds as dsProducts
          > ' Fill dataset
          > 'SELECT ProductID, SampleSize, Description, Grade, MoistureContent , Ash,
          >Rotten FROM Products WHERE ProductID BETWEEN COALESCE(-1, '@ProductID) AND
          >COALESCE(65535 , @ProductID)
          > For Each row as dsProducts.Prod uctsRow in dsProducts
          > Me.SampleSize = row.SampleSize
          > Me.Description = row.Description
          > etc.
          > Next
          > End Sub
          >End Class
          >
          >However, this is where I run into my mental "brick wall":
          >1) Should Class Product not just expose the dataset, saving me the effort of
          >the loop to fill the class properties with the row details?
          >2) How do I update Class Product? Assuming that I'm using a DataGridSource
          >(asp.net or win.forms), if the souce of these UI elements is a dataview, then
          >I can use all of ADO.Net's capababilities, i.e. Merge, GetChanges(data set)
          >etc.
          >
          >If I carry on down the road of my "Generics" model do I have to lose all the
          >"cool" things about ADO.Net? Alternativley, how do I model my "traditiona l
          >database oriented" design using Class Designer?
          >
          >I do hope that I have been able to clearly express my confusion, and hope
          >that someone could point me in the right direction.[/color]

          Firstly I'll state I haven't yet looked at the latest release of
          Visual studio so I'm not sure of the capabilities of the LIST object,
          but I assume you can inherit from it.

          Assuming you have an inherited list ProductList in your 'LIMS'
          (Laboratory Information Management System) with a private member
          dsProducts

          In your product class if you expose a friend property as
          dsProducts.Prod uctsRow then the load method (of the product
          collection) could look something like

          For Each row as dsProducts.Prod uctsRow in dsProducts
          Product.Product Row = Row

          Next
          Where Product is retried from the appropriate item of the list.

          Then the Friend ProductRow should be a copy of its data in the
          datatable. I personally don't like this approach as it tends to be
          very memory hungry.

          The alternative approach is in your class to track the state of the
          object i.e. is it a new object or one that has been retrieved from the
          database or has it been modified and then provide appropriate Insert
          Delete and Update methods.

          As in all of these things the best approach will depend on the
          environment you are working in and such factors as data ownership and
          data volumes.

          If the use of computers within a laboratory is of interest to you then
          there is a discusion group (the LIMS LIST) at
          Majordomo@lims. taratec.com
          [color=blue]
          >Many thanks
          >Jeremy Holt
          >[/color]

          Comment

          Working...