How to model subsets of relationships between objects
I'm new to domain models, so forgive me for asking a rudimentary question.
If a domain object has a 1-many relationship with another domain object, but the logic that uses the first object only works with a subset of the objects associated with the objects, what is the best way to expose that subset?
For example, let's say that Person is associated with many orders, but some external logic only needs to examine "Sent" orders associated with a Person. Should a person have a DispatchedOrders property along with other properties for other subsets (like CompletedOrders, etc.) or is this bad design? Suppose, for performance reasons, I cannot filter objects in memory and must use SQL to discard only the subset of interest.
thanks
If you are using SQL to find the collection you are interested in, you are in a perfect world. Relational queries are all you can find. Find the perfect query and then just figure out what the class of result tuples is, i.e. Object for each result tuple and processes them accordingly.
In your example, you need a set of "Sent Orders", which all information about a person should be linked to each.
a source to share
I think you have the right idea - DispatchedOrders will tell me what collection of object you are returning to me. As Kurt said, you are in a good place as you can use a SQL / stored procedure to retrieve your data.
One caveat - make sure the domain matches the business process and is not an interpolation of your understanding of the process. That is, why does a person have primacy over order and what angle did you draw when building other objects. The line also contains the order and this causes the object to bloat? Discussions with your client should help shape the answer.
Rob Conery of SubSonic fame has a good discussion of these types of problems . It's worth listening to.
a source to share