This is the first post of a series of posts that will try to highlight some of the typical UML errors I’ve seen, specially among my students. Therefore I think ALL novices (and others NOT so novices) can benefit from them. As always, suggestions are more than welcome.
To illustrate our first problem, imagine that you need to record information about the parents of the people stored in the system. Given this requirements, many would draw something like this:
At first sight, it seems like a reasonable solution, doesn’t it?. It says that all people can have zero or more children at that each person has two parents (some refine this a little bit to accept people with just one parent). So, where is the problem?
The problem is that this model forces the users to introduce an infinite number of parents for every person they introduce in the system!
This is easy to see with an example. Let’s assume that we INSERT a person named Albert in the system. According to the model we also need to record the information about Albert’s parents in order to satisfy the minimum multiplicity condition in the association isParentOf . So, we then insert two additional people (e.g. Joseph and Martha) as Albert’s parents. Now, since Joseph and Martha’s are also instance of Person, we need to insert four additional people in the system (Joseph’s parents and Martha’s parents). Do you see it already? After that we will need to insert the eight grandparents, then the 16 grand-grand-parents and so on.
The only way to stop the recursion is to say that somebody is (directly or indirectly) his/her own ancestor which obviously does not make sense.
Solution : the easiest way to avoid the problem is to weaken the multiplicity condition. Maybe in the real world, all people have parents but this cannot be true for the people recorded in the system. So a possible solution would be:
REMEMBER: reflexive associations with a minimum multiplicity constraint greater than 1 only make sense if the domain admits cycles among the instances of the class