Results 1 to 4 of 4

Thread: Should class properties be values or references to objects?

Threaded View

  1. #1

    Thread Starter
    Junior Member jamison's Avatar
    Join Date
    Jan 2005
    Posts
    26

    Should class properties be values or references to objects?

    Should class properties be values or references to objects?

    Here's my situation: Reseller Has Customers Has Services

    In my app, the relationship between objects rarely changes. So once a customer is setup for a given reseller, he will pretty much always have that association.

    I frequently do relational type operations such as getting the name of a reseller, when given only the customer or service.

    I would like to keep database hits to a minimum.


    #1. customer class should contain a reference object for the reseller
    VB Code:
    1. Public Class Customer
    2.   public CustID as integer '(readonly)
    3.   public ResellerID as integer
    4.   public Services as ServiceCollection
    5. End Class
    6.  
    7. 'To get the reseller's name from a Customer object
    8. dim theCustomer as new Customer(1)
    9. dim theReseller as new Reseller(theCustomer.ResellerID)
    10. strResellerName = theReseller.Name

    or #2. the resellers' key so that it can be retrieved if needed.
    VB Code:
    1. Public Class Customer
    2.   public CustID as integer '(readonly)
    3.   public Reseller as Reseller
    4.   public Services as ServiceCollection
    5. End Class
    6.  
    7. 'To get the reseller's name from a Customer object
    8. dim theCustomer as new Customer(1)
    9. strResellerName = theCustomer.Reseller.Name

    Right now I'm doing #1. It has benefits such as being able to the the reseller's name with statements like this: strName = theCustomer.Reseller.CompanyName. Unfortunately this is really starting to be a pain in the butt, since I have to set those references all the time. But at the same time, I'm only instantiating the Reseller object one time so there is only one database hit.

    Thanks for any opinions,
    Jamison
    Last edited by jamison; Oct 19th, 2005 at 03:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width