17

I have a question about association multiplicity. I understand it, but for example if I would have:

 ---------            ---------
|         |1      *  |         |
|CLASS    |----------| STUDENT |
|         |          |         |
 ---------            ---------

does that mean that at ANY point during system existence there must be at least 1 student assigned to the class, or those multiplicities should be true, if the system is operating normally?

I am asking this question, because I was wondering about the moment of creation for an object. First we create an empty class, then populate it with students. For some time the class is empty, but only during the creation and populating it will have has at least one student. If I changed 1 to 0..1 it would suggest there can be empty class. This isn't false (at the moment of populating) but later I don't want to permit classes with no students.

EDIT: changed 0..* to 0..1, it should be like it is now, sorry for confusion.

hat
  • 781
  • 2
  • 14
  • 25
Andna
  • 6,539
  • 13
  • 71
  • 120

3 Answers3

12

dose that mean that at ANY point during system existence there must be at least 1 student assigned to the class, or those multiplicities should be true, if the system is operating normally.

That's a good question. It means that, when the system is in a stable state, every Student MUST be associated with exactly one Class. That in turn raises another question: what constitutes a 'stable state'? UML in general doesn't formalise this. Intuitively, it means when there's no activity in progress that is actively changing state. Some profiles of UML put more rigour around this. For example, Executable UML says that the system can violate the cardinality constraints while the action of a state is executing. However when the state action completes it must leave the system in valid state, i.e. where all cardinality constraints are satisfied.

Databases provide a good analogy here. DB constraints (such as not null & foreign keys) must hold true when the system is stable. During the execution of a transaction the constraints may be temporarily violated. However, when the transaction completes, it must leave the db in a valid state.

So for your example as shown:

  • It is valid for a Class to exist with no Students when the system is stable (* says 0 or more - so Class need not have any Students)
  • It is not valid for a Student to exist without being assigned to a Class when the system is stable ('1' means exactly one). So whatever 'transaction' creates the Student must also associate the Student with a Class.

hth.

sfinnie
  • 9,854
  • 1
  • 38
  • 44
1

dose that mean that at ANY point during system existence there must be at least 1 student assigned to the class

It means there is exactly one class assigned to multiple students.

Each end of the association has an upper multiplicity boundary and a lower multiplicity boundary, but most UML editors will only show one value if the upper and lower boundaries are the same. If you want to allow (zero or one) to many, you can write it like this:

0..1      *  
-----------

What you really probably want here is a many-to-many relationship... students can be in many classes, and classes can contain many students.

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • about 2 year after, your answer answerd my question :) that is why there are 4 values in multiplicity. in hibernate, we only model this to many-to-one one-to-one one-to-many, only need 2 values. – lovespring Mar 30 '14 at 23:43
0

No,the * means not that there's at least one Student in each Class at any time. But the other direction, looking from Student to Class, the multiplicity means that any student is in exactly one Class.

For modelling reasons you might want to change the 1 multiplicity also to *, but this depends on your context.

Markus
  • 2,071
  • 4
  • 22
  • 44
  • Ok, but what about this "at any time", does this also exclude the situation I described (creation of an object), or are those situations ommited? – Andna Mar 10 '12 at 22:28
  • And about * - I think it means the same as 0..*, at least that what it says in "UML distilled" – Andna Mar 10 '12 at 22:36
  • @Andna it depends on how your UML editor interprets your input... you should be able to inspect the diagram and see that actual upper and lower boundaries for each endpoint. – Dagg Nabbit Mar 10 '12 at 22:40
  • I am using visual paradigm, and as far as my little skills in this software goes, if I select * as multiplicity I see only '*', but I think that this discussion about the meaning of * is not relevant to this topic, I fixed my original post, because there was an error concerning multiplicities (0..'**' instead of 0..1), if you could take a look at it now, I would be grateful :) – Andna Mar 10 '12 at 22:52