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:
Public Class Customer public CustID as integer '(readonly) public ResellerID as integer public Services as ServiceCollection End Class 'To get the reseller's name from a Customer object dim theCustomer as new Customer(1) dim theReseller as new Reseller(theCustomer.ResellerID) strResellerName = theReseller.Name
or #2. the resellers' key so that it can be retrieved if needed.
VB Code:
Public Class Customer public CustID as integer '(readonly) public Reseller as Reseller public Services as ServiceCollection End Class 'To get the reseller's name from a Customer object dim theCustomer as new Customer(1) 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




Reply With Quote