dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: some feedback on my design....

  1. #1
    mgergZ Guest

    some feedback on my design....


    Hi,

    I'm hitting the wall at the moment regarding any better ways of getting around
    this:

    I have three classes,
    <Products> collection object
    <Product> single object
    <ProdDataCon> object handling DB stuff.

    When the UI saves an object to DB, it is done through ProdDataCon, via Product,
    ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    on DB.
    Now at this time I want to add this Product to the collection, which is ofcourse
    in the Products object.

    To do it with this design, UI will have to pass the Products object as a
    param, which is received by the ProdDataCon object, and THEN PASSED ON AGAIN
    to the Products object to add to the collection.

    This to me is a bit much passing of objects back and forth, but as its the
    only way I can think of doing it, does anyone have any better ideas?? Is
    the design itself out-of-whack in the first place??

    Thanks
    MgergZ

  2. #2
    challis Guest

    Re: some feedback on my design....


    Hi,

    the sollution is actually quite simple.

    In the products class add a method called Add or AddNew (I usually have both).

    Public Function AddNew as clsProduct
    dim objProduct as clsProduct
    set objProduct = new clsProduct

    mcolProducts.add objProduct, [Key] '(The local collection object)

    set AddNew = objProduct
    End Function

    In the above objProduct still can save itself by calling the data class,
    but does not have to pass any objects. ie if you include a property called
    CollectionID to identify which collection the product belongs to (if you
    have multiple collections) Then in the collection collection you cann access
    the relevant parent collection by clsCollection.Item(CollectionID)

    challis
    set objProduct = Nothing
    "mgergZ" <mgergs@mbox.com.au> wrote:
    >
    >Hi,
    >
    >I'm hitting the wall at the moment regarding any better ways of getting

    around
    >this:
    >
    >I have three classes,
    ><Products> collection object
    ><Product> single object
    ><ProdDataCon> object handling DB stuff.
    >
    >When the UI saves an object to DB, it is done through ProdDataCon, via Product,
    >ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    >on DB.
    >Now at this time I want to add this Product to the collection, which is

    ofcourse
    >in the Products object.
    >
    >To do it with this design, UI will have to pass the Products object as a
    >param, which is received by the ProdDataCon object, and THEN PASSED ON AGAIN
    >to the Products object to add to the collection.
    >
    >This to me is a bit much passing of objects back and forth, but as its the
    >only way I can think of doing it, does anyone have any better ideas?? Is
    >the design itself out-of-whack in the first place??
    >
    >Thanks
    >MgergZ



  3. #3
    victor Guest

    Re: some feedback on my design....


    It looks like the object has to be saved first in database and then added
    to collection.

    AddNew adds and returns empty Product. Then it has to be populated with actual
    attributes and passed to database handler. If at some reason database operation
    failed you have to remove the object from collection.

    It sounds as UI behaves as Controller/Dispatcher: get object, populate it,
    pass it to save, if saved add it to appropriate collection. Everything is
    separated. What is the problem?

    It may be delay saving to database. Make it asynchronus. Generate event when
    object is saved and add it to collection there. UI will not need to wait
    until save operation completed.

    Victor

    "challis" <bmlx@yahoo.com> wrote:
    >
    >Hi,
    >
    >the sollution is actually quite simple.
    >
    >In the products class add a method called Add or AddNew (I usually have

    both).
    >
    >Public Function AddNew as clsProduct
    > dim objProduct as clsProduct
    > set objProduct = new clsProduct
    >
    > mcolProducts.add objProduct, [Key] '(The local collection object)
    >
    > set AddNew = objProduct
    >End Function
    >
    >In the above objProduct still can save itself by calling the data class,
    >but does not have to pass any objects. ie if you include a property called
    >CollectionID to identify which collection the product belongs to (if you
    >have multiple collections) Then in the collection collection you cann access
    >the relevant parent collection by clsCollection.Item(CollectionID)
    >
    >challis
    > set objProduct = Nothing
    >"mgergZ" <mgergs@mbox.com.au> wrote:
    >>
    >>Hi,
    >>
    >>I'm hitting the wall at the moment regarding any better ways of getting

    >around
    >>this:
    >>
    >>I have three classes,
    >><Products> collection object
    >><Product> single object
    >><ProdDataCon> object handling DB stuff.
    >>
    >>When the UI saves an object to DB, it is done through ProdDataCon, via

    Product,
    >>ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    >>on DB.
    >>Now at this time I want to add this Product to the collection, which is

    >ofcourse
    >>in the Products object.
    >>
    >>To do it with this design, UI will have to pass the Products object as

    a
    >>param, which is received by the ProdDataCon object, and THEN PASSED ON

    AGAIN
    >>to the Products object to add to the collection.
    >>
    >>This to me is a bit much passing of objects back and forth, but as its

    the
    >>only way I can think of doing it, does anyone have any better ideas?? Is
    >>the design itself out-of-whack in the first place??
    >>
    >>Thanks
    >>MgergZ

    >



  4. #4
    Arthur Wood Guest

    Re: some feedback on my design....


    MgregZ,

    I would suggest that you might find the following book of great interest:

    Visual Basic 6 Business Objects by Rockford Lhotka ISBN 1-861001-07-X

    He has implemented ALMOST this precise model, in the book.

    Arthur Wood


    "mgergZ" <mgergs@mbox.com.au> wrote:
    >
    >Hi,
    >
    >I'm hitting the wall at the moment regarding any better ways of getting

    around
    >this:
    >
    >I have three classes,
    ><Products> collection object
    ><Product> single object
    ><ProdDataCon> object handling DB stuff.
    >
    >When the UI saves an object to DB, it is done through ProdDataCon, via Product,
    >ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    >on DB.
    >Now at this time I want to add this Product to the collection, which is

    ofcourse
    >in the Products object.
    >
    >To do it with this design, UI will have to pass the Products object as a
    >param, which is received by the ProdDataCon object, and THEN PASSED ON AGAIN
    >to the Products object to add to the collection.
    >
    >This to me is a bit much passing of objects back and forth, but as its the
    >only way I can think of doing it, does anyone have any better ideas?? Is
    >the design itself out-of-whack in the first place??
    >
    >Thanks
    >MgergZ



  5. #5
    Arthur Wood Guest

    Re: some feedback on my design....


    Challis,
    Are you familiar with Rock Lhotka's book Visual Basic 6 Business Objects?
    He uses precisely the methodolgy you are describing.

    Arthur Wood


    "challis" <bmlx@yahoo.com> wrote:
    >
    >Hi,
    >
    >the sollution is actually quite simple.
    >
    >In the products class add a method called Add or AddNew (I usually have

    both).
    >
    >Public Function AddNew as clsProduct
    > dim objProduct as clsProduct
    > set objProduct = new clsProduct
    >
    > mcolProducts.add objProduct, [Key] '(The local collection object)
    >
    > set AddNew = objProduct
    >End Function
    >
    >In the above objProduct still can save itself by calling the data class,
    >but does not have to pass any objects. ie if you include a property called
    >CollectionID to identify which collection the product belongs to (if you
    >have multiple collections) Then in the collection collection you cann access
    >the relevant parent collection by clsCollection.Item(CollectionID)
    >
    >challis
    > set objProduct = Nothing
    >"mgergZ" <mgergs@mbox.com.au> wrote:
    >>
    >>Hi,
    >>
    >>I'm hitting the wall at the moment regarding any better ways of getting

    >around
    >>this:
    >>
    >>I have three classes,
    >><Products> collection object
    >><Product> single object
    >><ProdDataCon> object handling DB stuff.
    >>
    >>When the UI saves an object to DB, it is done through ProdDataCon, via

    Product,
    >>ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    >>on DB.
    >>Now at this time I want to add this Product to the collection, which is

    >ofcourse
    >>in the Products object.
    >>
    >>To do it with this design, UI will have to pass the Products object as

    a
    >>param, which is received by the ProdDataCon object, and THEN PASSED ON

    AGAIN
    >>to the Products object to add to the collection.
    >>
    >>This to me is a bit much passing of objects back and forth, but as its

    the
    >>only way I can think of doing it, does anyone have any better ideas?? Is
    >>the design itself out-of-whack in the first place??
    >>
    >>Thanks
    >>MgergZ

    >



  6. #6
    Richard Dalton . Guest

    Re: some feedback on my design....



    mgergZ

    Just a word of caution about Collections of objects.
    I assumed when I started doing object in VB, that I could
    write all the load and save code for an object once,
    and then use it to load and save collections for the
    objects. So the save method of the collection might
    be something like the following:

    For each obj in Me.Items
    Call obj.Save
    next obj

    Treating objects in a collection individualy like this
    is a recipe for disaster. The performance hit is just
    unbearable.

    It's much better to find a way of loading and saving
    collections in one go, using a recorset. It may mean
    duplicating some of the load/save logic from the object
    into the collection, but it will be worth it.

    -Richard








  7. #7
    mgergZ Guest

    Re: some feedback on my design....


    Thanks for the tips guys...



    "Richard Dalton" . wrote:
    >
    >
    >mgergZ
    >
    >Just a word of caution about Collections of objects.
    >I assumed when I started doing object in VB, that I could
    >write all the load and save code for an object once,
    >and then use it to load and save collections for the
    >objects. So the save method of the collection might
    >be something like the following:
    >
    > For each obj in Me.Items
    > Call obj.Save
    > next obj
    >
    >Treating objects in a collection individualy like this
    >is a recipe for disaster. The performance hit is just
    >unbearable.
    >
    >It's much better to find a way of loading and saving
    >collections in one go, using a recorset. It may mean
    >duplicating some of the load/save logic from the object
    >into the collection, but it will be worth it.
    >
    >-Richard
    >
    >
    >
    >
    >
    >
    >



  8. #8
    challis Guest

    Re: some feedback on my design....


    No, sorry. But I have read Dan Applemans book on COM/ActiveX and Deborah Kuratas
    Doing Objects in VB6. Neither of them specifically use the method I described,
    but I have had quite a bit of experience in OOP and solved similar problems
    often. TO me it seems the logical sollution (until I hear of a better one)

    challis

    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >Challis,
    > Are you familiar with Rock Lhotka's book Visual Basic 6 Business Objects?
    > He uses precisely the methodolgy you are describing.
    >
    >Arthur Wood
    >
    >
    >"challis" <bmlx@yahoo.com> wrote:
    >>
    >>Hi,
    >>
    >>the sollution is actually quite simple.
    >>
    >>In the products class add a method called Add or AddNew (I usually have

    >both).
    >>
    >>Public Function AddNew as clsProduct
    >> dim objProduct as clsProduct
    >> set objProduct = new clsProduct
    >>
    >> mcolProducts.add objProduct, [Key] '(The local collection object)
    >>
    >> set AddNew = objProduct
    >>End Function
    >>
    >>In the above objProduct still can save itself by calling the data class,
    >>but does not have to pass any objects. ie if you include a property called
    >>CollectionID to identify which collection the product belongs to (if you
    >>have multiple collections) Then in the collection collection you cann access
    >>the relevant parent collection by clsCollection.Item(CollectionID)
    >>
    >>challis
    >> set objProduct = Nothing
    >>"mgergZ" <mgergs@mbox.com.au> wrote:
    >>>
    >>>Hi,
    >>>
    >>>I'm hitting the wall at the moment regarding any better ways of getting

    >>around
    >>>this:
    >>>
    >>>I have three classes,
    >>><Products> collection object
    >>><Product> single object
    >>><ProdDataCon> object handling DB stuff.
    >>>
    >>>When the UI saves an object to DB, it is done through ProdDataCon, via

    >Product,
    >>>ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    >>>on DB.
    >>>Now at this time I want to add this Product to the collection, which is

    >>ofcourse
    >>>in the Products object.
    >>>
    >>>To do it with this design, UI will have to pass the Products object as

    >a
    >>>param, which is received by the ProdDataCon object, and THEN PASSED ON

    >AGAIN
    >>>to the Products object to add to the collection.
    >>>
    >>>This to me is a bit much passing of objects back and forth, but as its

    >the
    >>>only way I can think of doing it, does anyone have any better ideas??

    Is
    >>>the design itself out-of-whack in the first place??
    >>>
    >>>Thanks
    >>>MgergZ

    >>

    >



  9. #9
    challis Guest

    Re: some feedback on my design....


    Arthur

    No, sorry. But I have read Dan Applemans book on COM/ActiveX and Deborah
    Kuratas Doing Objects in VB6. Neither of them specifically use the method
    I described, but I have had quite a bit of experience in OOP and solved similar
    problems often. TO me it seems the logical sollution (until I hear of a better
    one)

    Richard

    I like the use of recordsets used for saving and loading collections, but
    then in the data tier implement a save method that accepts a recordset for
    saving. If there is one record (ie called from obj.Save as opposed to col.Save)
    it can save a single object at a time. This is handy when you wish to be
    able to save individual records at a time. Example a n Excel spreadsheet,
    you almost never wnat to or have need to save all workbooks and load all
    workbooks at a time relevant to a sollution. You want, ney need to only save
    one at a time.

    challis



    "mgergZ" <mgergs@mbox.com.au> wrote:
    >
    >Thanks for the tips guys...
    >
    >
    >
    >"Richard Dalton" . wrote:
    >>
    >>
    >>mgergZ
    >>
    >>Just a word of caution about Collections of objects.
    >>I assumed when I started doing object in VB, that I could
    >>write all the load and save code for an object once,
    >>and then use it to load and save collections for the
    >>objects. So the save method of the collection might
    >>be something like the following:
    >>
    >> For each obj in Me.Items
    >> Call obj.Save
    >> next obj
    >>
    >>Treating objects in a collection individualy like this
    >>is a recipe for disaster. The performance hit is just
    >>unbearable.
    >>
    >>It's much better to find a way of loading and saving
    >>collections in one go, using a recorset. It may mean
    >>duplicating some of the load/save logic from the object
    >>into the collection, but it will be worth it.
    >>
    >>-Richard
    >>
    >>
    >>
    >>
    >>
    >>
    >>

    >



  10. #10
    Richard Dalton . Guest

    Re: some feedback on my design....


    "challis" <bmlx@yahoo.com> wrote:
    >I like the use of recordsets used for saving and loading collections, but
    >then in the data tier implement a save method that accepts a recordset for
    >saving. If there is one record (ie called from obj.Save as opposed to col.Save)



    Yep, I agree.
    I don't use recordset's outside of the DB layer. But apart from
    that we are in agreement. I marshal data using XML. If I have a
    collection, I can extract an XML string which only includes the items
    that have changed. Or I can extract the XML for all items.

    The DB layer accepts the XML, and saves whatever items it's given.
    Same technique, different marshalling method.

    -Richard


  11. #11
    Arthur Wood Guest

    Re: some feedback on my design....


    Richard,
    Will it ALWAYS be the case that just because you have an object in your
    collection, it MUST be saved? You may find it more efficient to only save
    those objects whose data has changed. That my mean setting up an IsDirty
    property in the class, set it to true when a persistable property has changed,
    and then only save those objects for which IsDirty is true.

    I suspect that your application does not touch EACH and EVERY member of the
    collection. If that is the case, why spend the time saving all those objects
    which have not changed?

    Arthur Wood


    "Richard Dalton" . wrote:
    >
    >
    >mgergZ
    >
    >Just a word of caution about Collections of objects.
    >I assumed when I started doing object in VB, that I could
    >write all the load and save code for an object once,
    >and then use it to load and save collections for the
    >objects. So the save method of the collection might
    >be something like the following:
    >
    > For each obj in Me.Items
    > Call obj.Save
    > next obj
    >
    >Treating objects in a collection individualy like this
    >is a recipe for disaster. The performance hit is just
    >unbearable.
    >
    >It's much better to find a way of loading and saving
    >collections in one go, using a recorset. It may mean
    >duplicating some of the load/save logic from the object
    >into the collection, but it will be worth it.
    >
    >-Richard
    >
    >
    >
    >
    >
    >
    >



  12. #12
    challis Guest

    Re: some feedback on my design....


    Hi,

    I use disconnected recordsets, which can veryy easily be converted to XML.
    I am however curious how exactly you handle XML streams as you described
    below (especially for passing collection contained objects data); would you
    post or e-mail some sample/source code, I would greatly appreciate.

    challis


    "Richard Dalton" . wrote:
    >
    >"challis" <bmlx@yahoo.com> wrote:
    >>I like the use of recordsets used for saving and loading collections, but
    >>then in the data tier implement a save method that accepts a recordset

    for
    >>saving. If there is one record (ie called from obj.Save as opposed to col.Save)

    >
    >
    >Yep, I agree.
    >I don't use recordset's outside of the DB layer. But apart from
    >that we are in agreement. I marshal data using XML. If I have a
    >collection, I can extract an XML string which only includes the items
    >that have changed. Or I can extract the XML for all items.
    >
    >The DB layer accepts the XML, and saves whatever items it's given.
    >Same technique, different marshalling method.
    >
    >-Richard
    >



  13. #13
    Richard Dalton . Guest

    Re: some feedback on my design....


    "challis" <bmlx@yahoo.com> wrote:
    >I am however curious how exactly you handle XML streams as you described
    >below (especially for passing collection contained objects data); would


    >you post or e-mail some sample/source code, I would greatly appreciate.



    I hope the following makes sense.

    My CollectionClass (In this case CEmployeeCollection) has a GetXML
    method. It takes two parameters, and returns an XML representation
    of the collection.

    Public Function GetXML(
    Optional as_Tag As String = MODULENAME,
    Optional ab_IncludeAll As Boolean = True) As String


    Ignore as_Tag that just allows you to specify the name of the root
    XML node. It's not relevant to what we're discussing here, but I
    need it elsewhere. ab_Include all tell the method whether I want
    all the items, or only the changed items.

    Here's the important bit of code:

    ' Decide whether to return full XML, or only changed items
    If ab_IncludeAll Then
    ls_XML = mobj_Items.GetXML(as_Tag)
    Else
    Set obj_XML = New DOMDocument
    Call obj_XML.appendChild(obj_XML.createElement(as_Tag))
    For li_Item = 0 To mobj_Items.Count - 1
    Set obj_Item = mobj_Items.Item(li_Item)
    If obj_Item.Changed Then
    Set obj_XMLItem = New DOMDocument
    Call obj_XMLItem.loadXML(obj_Item.GetXML)
    Call obj_XML.childNodes(0).appendChild(obj_XMLItem.documentElement)
    End If
    Next li_Item
    ls_XML = obj_XML.xml
    End If


    mobj_Items is a CSet object. This is a wrapper for the VBDictionary.
    Among other things I've given it a GetXML method so If I have a
    CSet full of objects I can get an XML representation of the full CSet.

    If you only want the XML of the changed items I need to iterate through
    the CSet and pluck those items out. In doing so I create a DomDocument
    and build it using the XML of the individual changed items in the CSet.
    That's the Else part of the code.

    This was a temporary way of doing things. It works pretty well.
    At the moment I'm playing with the idea of actually storing the
    collection in XML form instead of in a CSet.

    -Richard


  14. #14
    Deborah Guest

    Re: some feedback on my design....


    Hi -

    The architecture we now use does the following:

    1) Data access class (one - not one per object) knows how to call any stored
    procedure given the stored procedure name and an param array of parameters.
    This class can be written to be completely database independent (thought
    it may be technology dependent ie. SQL Server). This class returns the data
    to the middle tier as XML.
    2) The middle tier component has features to modify/validate the XML as necessary.
    3) The UI tier (many times ASP), reads the XML to fill out the form and updates
    the XML with any changes from the user and ships it back.

    This is quite different from using collection classes and from Rocky's techniques.
    But I think this is closer to what we will be doing with .NET.

    Good luck!
    Deborah

    "mgergZ" <mgergs@mbox.com.au> wrote:
    >
    >Hi,
    >
    >I'm hitting the wall at the moment regarding any better ways of getting

    around
    >this:
    >
    >I have three classes,
    ><Products> collection object
    ><Product> single object
    ><ProdDataCon> object handling DB stuff.
    >
    >When the UI saves an object to DB, it is done through ProdDataCon, via Product,
    >ie, Product.Save calls ProdDataCon.Save, which actually does INSERT statement
    >on DB.
    >Now at this time I want to add this Product to the collection, which is

    ofcourse
    >in the Products object.
    >
    >To do it with this design, UI will have to pass the Products object as a
    >param, which is received by the ProdDataCon object, and THEN PASSED ON AGAIN
    >to the Products object to add to the collection.
    >
    >This to me is a bit much passing of objects back and forth, but as its the
    >only way I can think of doing it, does anyone have any better ideas?? Is
    >the design itself out-of-whack in the first place??
    >
    >Thanks
    >MgergZ



  15. #15
    Thomas Eyde Guest

    Re: some feedback on my design....

    What are the gain of using one data access class pr project? Aren't you
    migrating data knowledge to the middle tier (where I believed they didn't
    belong)?

    /Thomas

    "Deborah" <djk@no.com> wrote in message news:3a80f168$1@news.devx.com...
    >
    > Hi -
    >
    > The architecture we now use does the following:
    >
    > 1) Data access class (one - not one per object) knows how to call any

    stored
    > procedure given the stored procedure name and an param array of

    parameters.
    > This class can be written to be completely database independent (thought
    > it may be technology dependent ie. SQL Server). This class returns the

    data
    > to the middle tier as XML.





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center