I've been toying with many differnet inheritence strategies today, and I was hoping someone could point me to the Right Way to set it up.
I want a way to flag some classes as having a Calendar. It made sense to use an interface, so I called that Schedulable. Now suppose I have Resource, User, and Room that all need a Calendar. The primary keys are very different for Resource/User/Room.
Here are some solutions I came up with:
1. I was thinking of making a unidirectional one-to-one relationship from the three classes to Calendar:
Code:
Calendar
^
|
-----------------
| | |
Resource User Room
But then the Calendar can't go back to say the Resource referencing it.
2. I also tried making the Calendar have a relationship with the Schedulable interface:
Code:
Calendar----Schedulable
|
-----------------
| | |
Resource User Room
Then the Resource/User/Room need to do something with the schedulable id, but these classes are pretty much unrelated. I don't want the calendarId to be the primary key for any of the classes.
3. Use a discriminator for an association? This doesn't seem to exist by default in hibernate. For instance:
Code:
CALENDAR
---------------
Calendar ID | Foreign Key | RelationType
12 | Jimbo | User
13 | 112 | Resource
14 | H114 | Room
Any recommendations?