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

查看:82
本文介绍了如何在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类图中,我在PersonContract之间有很多关联.一个人可以涉及多个合同,反之,一个合同可以涉及多个人.每个参与人员都参与了合同中的角色.一个人甚至可以多次参与同一份合同中的不同角色:

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继承了多对多关系.但是,在与我的法律实践用户讨论之后,很快看来,CompanyFoundationContract中的Founder中的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关联类的特殊化,因此我希望清除一下,它是ContractPerson之间以及CompanyFoundationContract和之间的一个相同的关联. Founder.

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,并且那些属性与personcontract无关(除了它们的类型是专门化的).但是,如果您确实要重新定义它们,那么这些新属性(甚至可能具有相同的名称)将替换旧属性,从而使创始人不可能拥有非基础合同.

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}founder {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.

由于属性是默认设置,因此"set"设置为默认设置.意味着,它们不包含重复项,同一个人不可能在同一合同中扮演多个角色.如果希望做到这一点,则必须为属性设置属性{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天全站免登陆