I am currently creating a rich domain model at work and I have repeatedly come across a problem. There must be a common way of dealing with this, as I imagine it is a common situation. I will try to explain it with a simple domain model example:
Domain classes: Person, State, County
Relationships:
State has many counties
Person has many states (assume all people have residencies in multiple states)
The Person class has the following properties:
name :
String eyeColor : String
states : State[]
State has properties:
stateName : String
counties : County[]
The problem here is that when a Person has a residency in a state, it is in ONE county.
In the context of an association with Person, state should have one County. But when I add State as a property of the Person object, I get a State that can have multiple Counties. This is the problem I want to correct in my design.
Now, the only solution may be to only add one County (an array of one) to the State object when I create this family of objects, but this seems like a "duct tape" kind of solution. Any ideas?
Thanks