Newbie encapsulation question

Newbie encapsulation question

Old forum URL: forums.lhotka.net/forums/t/689.aspx


slipmat posted on Friday, July 21, 2006

Good OO programming encourages encapsulating all data that an object needs within the object, so I'm after feedback on the following simple scenario:
I have a QuoteInfo (RO) class, which basically has only 3 pieces of data:
GUID QuoteID
SmartDate CreationDate
Customer ??  (for ToString in the QuoteInfo object which will show FirstName, LastName & CompanyName if appropriate)
When pulling data from the Data Store, should I also get the FirstName, LastName, CompanyName fields from the Customer table in a SELECT / JOIN statement, or should I get an Instance of the CustomerInfo class with the CustomerID, and then use the Customer's own properties / tostring method to get the required name string?

Thanks for your input.

msk replied on Friday, July 21, 2006

I would normally put CustomerID and CustomerName in the QuoteInfo class in a situation like that.  Although you are probably denormalizing behaviour (having QuoteInfo contain CustomerInfo would be normalizing it) I think the gains in performance and in simplicity are worth it.  If your CustomerInfo class starts to get a lot of extra responsiblities that are also needed in your QuoteInfo class then the two class approach becomes more benificial. 

RockfordLhotka replied on Friday, July 21, 2006

I would default to loading the values directly into your QuoteInfo object - including the values from the customer table. It sounds like you are implementing a "display quote information" use case, and in that context the customer data is quote data.

slipmat replied on Sunday, July 23, 2006

Thank you for your input. I will take your advice.

Copyright (c) Marimer LLC