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

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

问题描述

我有一个关于关联多样性的问题.我了解这一点,但例如,如果我愿意:

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

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

这是否意味着在系统存在的任何时刻,必须至少有1名学生分配给该班级,或者如果系统运行正常,那么这些乘数应该为true?

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名学生分配给该班级,否则,如果系统运行正常,那么这些乘数应该为true.

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的某些配置文件对此更加严格.例如,可执行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.

数据库在这里提供了一个很好的类比.当系统稳定时,数据库约束(例如非null和外键)必须为true.在执行交易期间,约束可能会暂时违反.但是,当事务完成时,它必须使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"表示一个)的情况下,没有分配给班级的学生存在是无效的.因此,无论学生"如何创建学生,都必须将学生与班级联系起来.
  • 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.

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

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