On Sep 24, 10:06 pm, "BillG" <billgo...@charter.netwrote:
Say I have a class called Invoice. An invoice consists of a header and
detail lines. In my class called Invoice I have a member which is a object
of a collection of DetailLines, defined as follows:
public class Invoice
{
.....
List <DetailLinedetail;
}
When I retrieve an invoice, I also want to retrieve the detail lines. So do
I retrieve the detail lines in my method GetInvoice(long invoiceNo) in the
Invoice class or is it more proper to have an InvoiceController class that
first gets the Invoice and then gets the detail lines and populates the
member field in the Invoice class.
I realize that it works both ways, but what is the best way to do it.
Bill
The best way I personally think would be to encapsulate the fetching
of the detail lines in the invoice class. The invoice class might
delegate the actual fetching. The reason for this as that you might
end up with a "god" class (the controller class). The controller class
becomes a class that in itself has no information, but is purely there
to populate other objects. The temptation later could be to extend the
"god" class to do other work on the Invoice and InvoiceLine classes,
thus removing behaviour from the classes and the classes become pure
data carriers.
Here are a couple of links that might explain better:
http://en.wikipedia.org/wiki/God_object http://c2.com/cgi/wiki?GodClass http://www.pbell.com/index.cfm/2006/...eating-a-Class
Pieter