Search code examples
umlassociationsclass-diagram

Which type of relationship should I use?


I'm currently attending a class on UML diagrams where there are lab exercise which we need to complete.

In lab exercise, there are various data class in regards to the topic Supermarket. One of the data class is called Receipt which include attributes like id, payment datetime, purchased items and total price. There is also another data class called Payment which include a payment type attribute, Payment data class is "linked" to Receipt data class, however I'm not sure which relationship to use.

The full question paragraph is as follow:

Shopper arrives at checkout counter.
The total price is calculated and the shopper is given an receipt which includes a list of purchased items.
Payment is recorded when it occurs, either now (cash) or later (card payment).

Solution

  • Assuming that you make a class diagram:

    • The "link" is a simple association, since nothing in the wording suggests composition or aggregation.
    • "Payment is recorded when it occurs, either now or later" means that it is possible at some moment in time that there is no payment (yet) for a payment.
    • "either now (cash) or later (card payment)" strongly suggests that a receipt is paid with a single payment (multiple partial payments are not excluded by the wording, but it seems improbable).
    • so the multiplicity is 0..1 payments for a receipt.
    • Nothing is said about the multiplicity of receipts for a payment. We can imagine that there is a minimum of 1, since nobody would make a payment for nothing. But it cannot be excluded that a payment with a credit card is made for paying several unpaid receipts at once. I would therefore prudently let it unspecified in the diagram. In the real world, this is something that you would verify with your customer. In your exercise, depending of the practice you've witnessed from the professor, you may want to put a 1.

    So here the simplified diagram (I haven't shown properties and operations for the sake of simplicity, nor the items which you dodn't mention as a problem):

    enter image description here