1

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 :)

Christophe
  • 68,716
  • 7
  • 72
  • 138
alanb
  • 11
  • 1
  • The teacher's solution has been edited to be very different from what it was in the original question. Has the original intent of the question been lost?! – Jim L. May 10 '16 at 04:16
  • Welcome to StackOverflow, @alanb. If you found an answer to your question, please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) (by clicking the check-mark), and consider up-voting it (by clicking the up arrow). Accepting an answer indicates to the wider community that you've found a solution, gives yourself some reputation points, and gives some reputation points to the person who answered your question. If you did not find a satisfactory answer to your question, please leave a comment. – Jim L. May 13 '16 at 02:30

2 Answers2

2

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?

Jim L.
  • 6,177
  • 3
  • 21
  • 47
  • In "normal" business I would agree. But without knowing the domain the answer is unknown. There might be a business where you have a single order that has many customers. – qwerty_so May 09 '16 at 13:18
  • I think the question is where to put the multiplicities. – Jim L. May 09 '16 at 13:18
  • Yes. But the teacher can be right if you have a couple of people that place a single order. Unusual, but possible. – qwerty_so May 09 '16 at 13:20
  • The OP told us, "one customer has 0 - x orders and one order always belongs to one specific customer". – Jim L. May 09 '16 at 13:25
  • Thanks for the answers guys. Now I know that I'm on the right way :) – alanb May 10 '16 at 20:38
  • @alanb: You can show your appreciation by accepting and upvoting! – Jim L. May 10 '16 at 22:10
0

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.

Gerald Mücke
  • 10,724
  • 2
  • 50
  • 67