如何在 UML 中对协变关联类建模? [英] How to model a covariant association-class in UML?

查看:32
本文介绍了如何在 UML 中对协变关联类建模?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为两个类之间的协变关联建模,每个类都可以专门化.我需要展示相关关联类的专业化.但我想避免我的模型可能意味着存在冗余关联(即泛化之间的关联和特化之间的关联.

I would like to model a covariant association between two classes, that can each be specialized. I need to show the specialization of the related association-classes. But I want to avoid that my model could mean that there are redundant associations (i.e. one between the generalizations and one between the specializations.

我在 UML 类图中有一个 Person 和一个 Contract 之间的多对多关联.一个人可以涉及多个合同,反之,一个合同可以涉及多个人.每个相关人员都参与了合同中的角色.一个人甚至可以多次参与同一合同中的不同角色:

I have in an UML class diagram a many-many association between a Person and a Contract. A person can be involved in several contracts, and conversely a contract can involve several persons. Each involved person ins involved with a role in the contract. One person can even be involved multiple time with different roles in the same contract:

有很多种Contract 专业化.让我们来看看CompanyFoundationContract,几个人决定创建一家公司.Person 也可以是特化的.这里我使用了一种特殊的人,叫做Founder.在实践中,我更喜欢组合而不是继承,创始人将是一个装饰者.但为了简化起见,我稍后会省略这个细节:

There are many kind of Contract specializations. Let's take a look at CompanyFoundationContract, where several persons decide to create a company. Person can also be specialized. Here I use a special kind of person called Founder. In practice, I prefer composition over inheritance, and the founder would be a decorator. But I'll omit this detail later for the sake of simplification:

从 UML 专业化,我知道 FounderCompanyFoundationContract 继承了多对多关系.但是在与我的法律实践用户讨论后,很快就发现FounderCompanyFoundationContract中的Role也需要专门化,例如考虑到公司持有的股份.在我的类图中对这种协方差建模似乎很简单:

From the UML specialization, I know that Founder and CompanyFoundationContract inherit the many-to-many relation. But after discussion with my users of the legal practice, It soon appears that the Role of a Founder in a CompanyFoundationContract needs to be specialized as well, to takie into account for example the shares held in the company. It seems simple to model this covariance in my class diagram:

乍一看,该模型可以代表此类合同的法律复杂性:很明显,非创始人的其他人可以以正常角色(例如注册公司的公证人或律师)参与合同.

At first sight, this model can represent the legal complexity of such contracts: it seems obvious that other persons that are not founders can be involved in the contract with a normal role (e.g. the notray or attorney who registers the company).

由于关联类 ShareHolderRoleRole 关联类的特化,我希望清楚它是 之间的一个相同关联合同Person以及CompanyFoundationContractFounder之间.

Since the association-class ShareHolderRole is a specialization of the Role association-class, I'd expect to clear that it's one and the same association between Contract and Person and between CompanyFoundationContract and Founder.

但是,我担心我错过了一些东西,并且严格解释 UML 会暗示有两个不同的冗余关联.我该如何准确建模只有一个关联,但有一个协变关联类?

However, I am worried that I missed something and that interpreting UML strictly would imply to have two different and redundant associations. How shall I model accurately the fact that there is only one association, but a covariant association-class?

推荐答案

一个专门的关联类并不仅限于连接重新定义的属性.所以,这个关联类完全有可能连接FounderfoundationContract,而那些属性与person无关合同(除了它们的类型是特化).但是,如果您重新定义它们,那么这些新属性(甚至可以具有相同名称)将替换旧属性,从而使创始人不可能拥有非基金会合同.

A specialized association class is not restricted to connect only redefined attributes. So, it is perfectly possible, that this association class connects founder and foundationContract, and those attributes have nothing to do with person and contract (except that their types are specializations). If you however do redefine them, then these new attributes (which even could have the same name) replace the old attributes, making it impossible for a founder to have non foundation contracts.

现在,基金会合同仍然是合同.因此,一个人参与的合同清单应该包含他们.这可以通过子集化来实现.只需定义一个 foundationContract {subsets contract}创始人 {subsets person}.我想,这才是你真正想要的.

Now, a foundation contract is still a contract. Therefore, the list of contracts a person is involved in, should contain them. This can be achieved with subsetting. Just define, that a foundationContract {subsets contract} and founder {subsets person}. I think, this is what you really wanted.

由于属性是每个默认设置,并且设置"是默认设置.意味着,它们不包含重复项,同一个人不可能在同一份合同中扮演多个角色.如果您希望这成为可能,您必须为属性设置属性 {nonunique}.

Since attributes are per default sets, and "set" means, they don't contain duplicates, it is not possible for the same person to play multiple roles in the same contract. If you want this to be possible, you have to set the property {nonunique} for the attributes.

这篇关于如何在 UML 中对协变关联类建模?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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