### Define derived role using OCL Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/FreeRole/index.html Use this OCL expression to set a free role as derived based on specific conditions. ```OCL context FreeRole-1 :: allInstances() : Set(FreeRole-1) derive : DefinedRole.allInstances()- >select( x | ) ``` -------------------------------- ### Define OCL derivation rule for Formal relation Source: https://ontouml.readthedocs.io/en/latest/relationships/formal/index.html Use this OCL rule to specify how a formal relation is derived based on the comparison of quality values. ```OCL context Person::lighter : Set(Person) derive : Person.allInstances()->select(x | self.weight > x.weight) ``` -------------------------------- ### OCL template for implicit rigid subtype derivation Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/HetColl/index.html Use this OCL template during refactoring to define a new rigid subtype derived from the negation of existing rigid subtypes. ```OCL context NewRigid::allInstances() : Set(NewRigid) derive : RigidParent.allInstances()- >select( x | not(x.oclIsTypeOf(Rigid_1 _) or x.oclsIsTypeOf(Rigid_ 2 _) or … or x.oclIsTypeOf(Rigid_ n _)) ``` -------------------------------- ### OCL Left Universal Composition Invariant Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelComp/index.html Enforces that type B has a left universal composition to type A. ```OCL context BSource inv: self.bTarget->asSet()->forAll( y | ASource.allInstances()->forAll( z | z.aTarget->asSet()->contains(y) implies z.aTarget->asSet()->contains(self)) ``` -------------------------------- ### OCL Right Universal Composition Invariant Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelComp/index.html Enforces that type B has a right universal composition to type A. ```OCL context BSource inv: self.bTarget->asSet()->forAll( y | ASource.allInstances()->forAll( z | z.aTarget->asSet()->contains(self) implies z.aTarget->asSet()->contains(y)) ``` -------------------------------- ### Define Redefine Constraint in OCL Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelSpec/index.html Use this OCL invariant when all elements related through A must also be related through B. ```OCL context BSource inv subset : self.oclAsType(ASource).aTarget=self.bTarget.oclAsType(ATarget) ``` -------------------------------- ### Define Uniqueness Constraint (Current Relator) Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RepRel/index.html OCL invariant to limit the number of coexistent relator instances that mediate the same combination of types. ```OCL context Relator inv: Relator.allInstances()- >select( r | r <> self and r.type1 = self.type1 and r.type2=self.type2)- >size() = ``` -------------------------------- ### Define Subset Constraint in OCL Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelSpec/index.html Use this OCL invariant when being connected through relation B implies being connected through relation A. ```OCL context BSource inv subset : self.oclAsType(ASource).aTarget- >includesAll(self.bTarget.oclAsType(ATarget) ``` -------------------------------- ### Enforce Multiplicity Constraint with OCL Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/ImpAbs/index.html Use this OCL invariant to restrict the number of instances of a specific subtype that a source class instance can be connected to. ```OCL context Source inv: let sub1Size = self.target->select( x | x.oclIsTypeOf('Target Subtype-1'))->size() in sub1Size >= min1 and sub1Size <= max1 ``` -------------------------------- ### OCL Custom Existential Composition Invariant Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelComp/index.html Enforces that type B has a custom existential composition to type A with a specific cardinality constraint. ```OCL context BSource inv: self.bTarget->asSet()->forAll( y | ASource.allInstances()->select( z | z.aTarget->asSet()->contains(y) and z.aTarget->asSet()->contains(self))->size()[>|<|=]n) ``` -------------------------------- ### OCL Exclusiveness Invariant Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelOver/index.html Use this OCL template to enforce that an individual cannot play multiple roles with respect to the same relator instance. ```OCL context Relator inv: self.over1.oclAsType(Supertype)- >asSet()->excludesAll( self.over2.oclAsType(Agent)- >asSet() and self.over1.oclAsType(Supertype)- >asSet()->excludesAll( self.over3.oclAsType(Agent)- >asSet() and self.over2.oclAsType(Supertype)- >asSet()->excludesAll( self.over3.oclAsType(Agent)- >asSet())) ``` -------------------------------- ### Define OCL Derivation for Intersection Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/DecInt/index.html Use this OCL constraint to specify that the extension of a type is derived by the intersection of the extensions of two or more concrete parents. ```OCL context Parent1 inv: (self.oclIsTypeOf(Parent2) and self.oclIsTypeOf(Parent2)) implies self.oclIsTypeOf(Type) ``` -------------------------------- ### Define Uniqueness Constraint (Historical Relator) Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RepRel/index.html OCL invariant and helper function to limit the number of concurrent relator instances over time. ```OCL context Relator inv: Relator.allInstances()- >select( r | r<>self and r.type1=self.type1 and r.type2=self.type2 and concurrent(self,r))- > size()= context Relator::concurrent(r:Relator):Boolean body: self.start = r.start or (self.start asSet()->forAll( y | ASource.allInstances()->exists( z | z.aTarget->asSet()->contains(self) and z.aTarget->asSet()->contains(y)) ``` -------------------------------- ### Define Disjoint Constraint in OCL Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelSpec/index.html Use this OCL invariant when being related through B implies not being related through A. ```OCL context BSource inv subset : self.oclAsType(ASource).aTarget- >excludesAll( self.bTarget.oclAsType(ATarget) ``` -------------------------------- ### OCL Exclusiveness Invariant Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/PartOver/index.html An OCL invariant template used to forbid an individual from playing multiple roles with respect to the same part instance. ```OCL context Part inv: self.over1.oclAsType(Supertype)->asSet()->excludesAll( self.over2.oclAsType(Agent)->asSet() and self.over1.oclAsType(Supertype)->asSet()->excludesAll( self.over3.oclAsType(Agent)->asSet() and self.over2.oclAsType(Supertype)->asSet()->excludesAll( self.over3.oclAsType(Agent)->asSet()) ``` -------------------------------- ### OCL Forbidden Composition Invariant Source: https://ontouml.readthedocs.io/en/latest/anti-patterns/RelComp/index.html Enforces that type B has a forbidden composition to type A. ```OCL context BSource inv: self.bTarget->asSet()->forAll( y | ASource.allInstances()->forAll( z | not(z.aTarget->asSet()->contains(y) and z.aTarget->asSet()->contains(self))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.