UML 关联多重性 [英] UML association multiplicity

查看:55
本文介绍了UML 关联多重性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于关联多重性的问题.我理解,但例如,如果我有:

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

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

这是否意味着在系统存在期间的任何时候都必须至少有 1 个学生被分配到班级,或者如果系统运行正常,这些多重性应该是真的?

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?

我问这个问题是因为我想知道对象的创建时刻.首先我们创建一个空类,然后用学生填充它.有一段时间班级是空的,但只有在创建和填充期间它才会有至少一个学生.如果我将 1 更改为 0..1,则表明可能存在空类.这不是错误的(在填充时)但后来我不想允许没有学生的课程.

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.

将 0..* 更改为 0..1,应该是现在这样,抱歉混淆.

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

推荐答案

这意味着在系统存在期间的任何时候都必须至少有 1 个学生被分配到班级,或者如果系统运行正常,这些多重性应该是真的.

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.

这是个好问题.这意味着,当系统处于稳定状态时,每个学生必须恰好与一个班级相关联.这反过来又提出了另一个问题:什么是稳定状态"?UML 通常不会将其形式化.直观地说,这意味着没有正在进行的活动正在积极改变状态.UML 的一些概要对此进行了更严格的处理.例如,Executable UML 表示系统可以在执行状态操作时违反基数约束.然而,当状态动作完成时,它必须使系统处于有效状态,即满足所有基数约束.

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.

数据库在这里提供了一个很好的类比.当系统稳定时,DB 约束(例如非空和外键)必须为真.在事务执行期间,可能会暂时违反约束.但是,当事务完成时,它必须使数据库处于有效状态.

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:

  • 当系统稳定时,没有学生的班级存在是有效的(* 表示 0 或更多 - 所以班级不需要任何学生)
  • 当系统稳定时,如果学生没有被分配到班级,则学生存在是无效的(1"表示正好是 1).因此,无论创建什么事务",学生还必须将学生与班级相关联.
  • 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.

这篇关于UML 关联多重性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆