How to model a covariant association-class in UML?

╄→гoц情女王★ 提交于 2020-07-22 10:59:20

问题


In short

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.

Step by step explanation of the problem

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:

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:

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).

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.

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?


回答1:


(you have a typo in your diagram using Founders)

I'd expect to clear that it's one and the same association between Contract and Person and between CompanyFoundationContract and Founder

not for me, else that means it is not possible to have that association as an additional one but of course this is possible

if you want to make that clear add the name of the association ends and use the same couple of names :

you can also explicitly say each association end redefines the other, allowing to use different names :

or of course you can do in the same way I do in the 'source' answer :

where the constraints in blue concern the relation-class rather than just the corresponding classes, and the constraints in green are not mandatory because they can be deduced from the constraints in blue




回答2:


"One person can even be involved multiple time with different roles in the same contract" - Role should not be binary, but ternary association between Person, Contract and RoleType.



来源:https://stackoverflow.com/questions/62973692/how-to-model-a-covariant-association-class-in-uml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!