Hi - I am new to Domain Modelling so forgive me for asking a couple of elementary questions. My first question is about knowing when to model domain relationships. I find sometimes I feel like all classes appear to be related in some way to most others and I am unclear about when I should model these relationships directly (by holding a reference in one class to another).
For example, say I have a Person class that is related to a collection of Orders and each Order is related to a collection of Products (forgive the unimaginative example). Each od these entities had a corresponding table in the database. If I am writing some client logic that deals with the Products that a Person is associated with (through that persons orders) it seems temping to have a Person.Products collection, especially as I could craft some SQL to get this collection without the need to pull back the Persons Orders collection. Is this OK or bad design? If what would be the better way to handle this?
Secondly, what about situations where relationships are contextual in nature? Continuing with the previous example say that some business logic that I want to run in a person method needs to deal with all of the Person's associated Orders that contain a specific Product (i.e. a subset of the Person's Orders collection). I can construct some SQL that will return exactly this subset very easily. The question is where do I expose the results? Should I put a method on Person that takes a Product parameter and returns the Orders collection so that client code looks like this?
person.OrdersContaining(Product p)
Should entities have multiple methods like this to expose different subsets of their relationships or should a Person just have a single Orders collection and subsets be handled in some other way?
Thanks