There are several ways to represent EITHER regarding associations in UML class diagrams:
- If the alternative associations are with similar in kind of "things", the specialization, is an interesting and powerful candidate: it often allow to expresses an implicit reality and can be structurally enforced.
- If the alternative associations are with unrelated "things", the use of an
{XOR}
is a pragmatic approach.
- Other possibilitites involve more advance UML features such as the use of subsetting or redefining.
Your diagram is based on specialization, since the singer and the band are a specialization of the same idea of producer. The diagram nevertheless needs some improvements:
Your usage of generalisation accurately expresses that a Producer
is a Singer
or a Band
.
But this allows also a situation where there is no SInger no Band, but just a Producer. If you want to express that Producer
itself is only an abstract concept that must be specialized, you should make it as an abstract class with its name in italic.
You should not repeat the properties of Producer
in Singer
and Band
: these are inherited and do not need to be explicitly repeated. Show in the specialization only properties that are not common.
Your usage of composition (black diamond) is incorrect: this would mean that an Album
is a part of its Producer
and that if its producer disappears, so does the album. Prefer the use of a simple association, with a 1
(or a 0..1
?) multiplicity on the Producer
end, and a *
multiplicity on the Album
end.
The association class Track
expresses very well the relation between a Song and the Album on which it is. By the way, the line between the association line and the association class symbol should be dotted.
Useful readings, considering your focus on database modeling: