Hi, given the following facts:
- groups and individuals share a M:N relationship
- groups can contain other groups; the group to group relationship is also M:N
how might this be modelled? I thought of using the composite pattern (where individual would be a subclass of group, and group contains multiple groups), but this isn't a composition relationship, because an individual can be a part of many groups (child with many parents). Same with group to group relationships...a subgroup can be a part of many containing groups.
So the following implied solution doesn't seem good at all:
- Group to Individual is M:N
- Group to Group is M:N
The application code would look totally ugly: to perform an action on a group, first you'd have to search all subgroups recursively, then get all individuals associated with each group, then perform the action on all of the above... (Not to mention the trouble of checking that you're not performing the same action more than once on a given individual, based on the cyclic potential of these relationships...)
Is it just me, or does that seem really 'un-elegant'? How would you model this? Any insight into this problem would be appreciated.
Thanks.