Quite new to OCL, thanks for the help.
So I have a profile with the stereotypes as shown:
Can someone tell me how to write an invariant constraint that says any association that is Coloured means that all connected classes must have the same colour value in their colour property?
I had this so far:
Context UML::InfrastructureLibrary::Core::Constructs::Association
inv: Association.allInstances() -> forAll(a:Association|a.oclIsTypeOf(Coloured) implies
a.associatedElement.colour = a.colour)
Pretty sure this is wrong because a.associatedElement does not exist.. but I do not understand how to access this 'all connected classes' or what that means. Perhaps I need something like
a.[association].colour
?
Thanks
From the UML spec (2.4.1 Superstructure, Sec. 7.3.3):
So, something like this:
I doubt that's the exact statement, but it should get you started in the right direction.
Your diagram should specify the constraint as well. Just attach a note to your Coloured stereotype saying if the instance is an association both connected class objects have to have the same colour property.