Wrong cardinality in UML class diagram

535 Views Asked by At

My school teacher and me are arguing about how to write the correct cardinality to a relation between two classes:

    Customer ----places->---- Order

So the exercise tells me, that one customer has 0 - x orders and one order always belongs to one specific customer. So my idea was:

    Customer -1---places->---*- Order

My teachers solution:

    Customer -1..*---places->---*- Order

So, what do you think about it? I hope, I'm right :)

2

There are 2 best solutions below

6
On

The first one is correct. The 0..*, or just * for short, goes next to the Order class. The 1..1, or just 1 for short, goes next to the Customer class.

Are you sure your teacher specified UML?

1
On

You are right.

The 1:n relationship you're describing, states, that 1 Customer placed 0..n Orders. There may be Customers without an order, but if there is an order, there is one customer. One order must have 1 and only 1 customer. This totally makes sense to me.

The 1..n:? solution is broken in various respects. First, the Order side has no cardinality. But there is no default defined by specfication. Of course a diagram does not have to contain a cardinality, but a diagram is also just a view on the model. If you leave the cardinality out without mentioning it elsewhere it's undefined. Further, the 1..n cardinality states, that an Order has been placed by 1 or more Customers. Assuming the excercise relates to some real-world problem, this seems totally pointless to me.