Domain model for an optional many-many relationship
Posted
by Greg
on Stack Overflow
See other posts from Stack Overflow
or by Greg
Published on 2010-05-03T19:39:53Z
Indexed on
2010/05/03
20:18 UTC
Read the original article
Hit count: 279
object-oriented-design
|many-to-many
Let's say I'm modeling phone numbers. I have one entity for PhoneNumber
, and one for Person
. There's a link table that expresses the link (if any) between the PhoneNumber
and Person
. The link table also has a field for DisplayOrder
.
When accessing my domain model, I have several Use Cases for viewing a Person
.
- I can look at them without any
PhoneNumber
information. - I can look at them for a specific
PhoneNumber
. - I can look at them and all of their current (or past)
PhoneNumbers
.
I'm trying to model Person
, not only for the standard CRUD operations, but for the (un)assignment of PhoneNumbers
to a Person
. I'm having trouble expressing the relationship between the two, especially with respects to the DisplayOrder
property. I can think of several solutions but I'm not sure of which (if any) would be best.
- A
PhoneNumberPerson
class that has aPerson
andPhoneNumber
property (most closely resembles database design) - A
PhoneCarryingPerson
class that inherits fromPerson
and has aPhoneNumber
property. - A
PhoneNumber
and/orPhoneNumbers
property onPerson
(and vis-a-versa, aPerson
property onPhoneNumber
)
What would be a good way to model this that makes sense from a domain model perspective? How do I avoid misplaced properties (DisplayOrder
on Person
) or conditionally populated properties?
© Stack Overflow or respective owner