Search code examples
umlassociationslanguage-lawyercovarianceclass-diagram

How to model a covariant association-class in UML?


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:

enter image description here

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:
enter image description here

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:

enter image description here

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?


Solution

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

    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.

    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.