If I have the following:
Public Class Product
Public Id As Integer
Public Name As String
Public AvailableColours As List(Of Colour)
Public AvailableSizes As List(Of Size)
End Class
and I want to get a list of products from the database and display them on a page along with their available sizes and colours, should I
a) have one method (GetProducts()) which makes use of a single view that joins the relevant tables, that then loops through each row and creates the objects as required?
or
b) have several methods which are responsible only for creating one object each? eg. GetProducts(), GetAvailableColoursForProduct(id), etc
I'm currently doing a) but as I add other other properties (multiple images, optional tassels, etc) the code is getting very messy (having to check that this isn't the same product as the previous row, has this colour already been added, etc) so I'm tempted to go with b) however, this will really ramp up the number of round trips to the database.
Cheers