RelComp anti-pattern
- Full name
Relation Composition
- Type
Logical
- Feature
Association
- Description
- Consider two associations, no matter their stereotypes:
A, that connects ASource and ATarget; and B, that connects BSource and BTarget.
- For this anti-pattern to occur, one of the possible statements needs to be true:
BSource equals or is a subtype of ATarget and BTarget equals or is a subtype of ATarget. BSource equals or is a subtype of ASource and BTarget equals or is a subtype of ASource.
- Justification
The instantiation of the two relations identified in this anti-pattern may restrict one another.
- Contraints
A and B are different associations.
The association A must have a minimum cardinality greater than 0 and a maximum greater than 1 in the association end connected to ATarget.
One of the following sentences must evaluate to true:
\[\begin{split}(ATarget = BSource \ \lor \ ancestorOf(ATarget,BSource)) \land \\ (ATarget = BTarget \ \lor \ ancestorOf(ATarget, BTarget))\end{split}\]\[\begin{split}(ASource = BSource \ \lor \ ancestorOf(ASource,BSource)) \land \\ (ASource = BTarget \ \lor \ ancestorOf(ASource, BTarget))\end{split}\]
- Examples
- Refactoring Plans
[OCL] Set Existential Composition: add an OCL invariant to enforce that type B has an existential composition to type A:
context BSourceinv: self.bTarget->asSet()->forAll( y |ASource.allInstances()->exists( z |z.aTarget->asSet()->contains(self) andz.aTarget->asSet()->contains(y))[OCL] Set Right universal Composition: add an OCL invariant to enforce that type B has a right universal composition to type A:
context BSourceinv: self.bTarget->asSet()->forAll( y |ASource.allInstances()->forAll( z |z.aTarget->asSet()->contains(self) impliesz.aTarget->asSet()->contains(y))[OCL] Set Left Universal Composition: add an OCL invariant to enforce that type B has a left universal composition to type A:
context BSourceinv: self.bTarget->asSet()->forAll( y |ASource.allInstances()->forAll( z |z.aTarget->asSet()->contains(y) impliesz.aTarget->asSet()->contains(self))[OCL] Set Forbidden Composition: add an OCL invariant to enforce that type B has a forbidden composition to type A:
context BSourceinv: self.bTarget->asSet()->forAll( y |ASource.allInstances()->forAll( z |not(z.aTarget->asSet()->contains(y) andz.aTarget->asSet()->contains(self)))[OCL] Set Custom Existential Composition: add an OCL invariant to enforce that type B has a custom existential composition to type A:
context BSourceinv: self.bTarget->asSet()->forAll( y |ASource.allInstances()->select( z |z.aTarget->asSet()->contains(y) andz.aTarget->asSet()->contains(self))->size()[>|<|=]n)
References:
Prince Sales, Tiago. (2014). Ontology Validation for Managers.