umlpapyrus

Which class diagram is correct: with or without inheritance?


This customer needs to have one payment account. I'm not sure whether it works to have customer having one inherited class. These are my two ideas:

Without Inheritance:

With Inheritance

With Inheritance:

Without Inheritance


Solution

  • In the model without inheritance, a customer could have both a bank account and a credit card. You could add an --{xor}-- constraint between the associations if a customer can only have either one.

    The diagram with inheritance clearly shows that a customer cannot have both a bank account and a credit card. But it also demands that each customer has an account. If there are customers without any account, then you should replace multiplicity "1" by "0..1".