UML association multiplicity

前端 未结 3 1085
没有蜡笔的小新
没有蜡笔的小新 2020-12-28 17:49

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

 ---------            ---------
|         |1      *  |            


        
3条回答
  •  死守一世寂寞
    2020-12-28 18:31

    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.

提交回复
热议问题