• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Relationships in Domain Model - Best Way to Model this Scenario?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about adding an "Address" or "Residency" class, which encapsulates the one-county rule?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this can be reasonable answered without knowing more about the application. Remember, objects are more about *behaviour* than about data. So, what does the system need *to do* with the state associated to a person? What does it need to do to counties?
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic