Which class diagram is correct: with or without inheritance?

345 views Asked by At

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

1

There are 1 answers

0
www.admiraalit.nl On BEST ANSWER

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".