-1

I am working on a small project and I tried to represent the following two requirements in my diagram:

  1. An album may be performed by either a singer or a band (not both). My plan to implement this requirement is to create a producer class that combine both singers and bands to guarantee that only one of them has performed that specific album.

  2. TEach album has many tracks on it that are numbered sequentially, usually up to 20. Each track of an album usually corresponds to a song. I have put an association class called track between song and album that includes trackID.

Does my representation correctly represent these two requirements? enter image description here

2

1 Answer 1

2

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:

4
  • Thank you for your answer. I have some questions regarding the producer class, as you suggested to make it an abstract class. I understood that concept but still confused about the next point. Do you mean if there are no special attributes for this class, I should keep the attributes space empty? Also, I would like to add the following requirements related to singer, band and album to make it clearer to you:1) Each singer has a unique ID, a name, and an address. 2) A band has ID and name. 3) Each album has a title, a release date, and a unique album number. Thanks
    – aa2004msf
    May 16, 2021 at 0:37
  • @aa2004msf abstract means that the class cannot itself be instantiated. This means that you can have dingers and bands that are kind of producers, but you cannot have producers that are just producers. This does not change anything about its properties. Keep in producer whats’s common. One question is whether you’ll have one unique ID for producers or if the ID is unique for singers and band (but a band could have the same id than a singer). But this will matter only for the inheritance table mapping. For req 1) you’d add address propety only in singer. For 3) add anything missing to the album
    – Christophe
    May 16, 2021 at 0:59
  • Producers will not have a unique ID, the ID of either singer or band is inherited, meaning that (the ID is unique for singers and band). One question, based on this, what properties should be in the producer class? Thanks
    – aa2004msf
    May 16, 2021 at 5:29
  • @aa2004msf id and name in producer, address in singer, nothing in band ( all needed properties are inherited ).
    – Christophe
    May 16, 2021 at 9:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.