UML/SysML: OCL specification of a derived property counting the number of a specific relation/stereotype

Viewed 343

I'm currently working on a UML/SysML profile (using the Cameo Systems Modeler (NoMagic)).

I created two new stereotypes. One is a new relationship with the metaclass dependency «collaborates» and the other is a class stereotype called «SystemGroup».

I then added a derived attribute to the «SystemGroup» stereotype called "/size". The idea is that this property is derived by the number of Systems which are connected to the SystemGroup via the new «collaborates» stereotype.

I think that shouldn't be to difficult using OCL (or maybe even the Expressions of the tool?). I'm an absolute beginner in MBSE, the OCL specification and Google didn't help so far since the specification is really detailed and answers on google are mostly general like "a derived property is a property which is derived by a specific expression in OCL or other languages".

Can somebody help me or send me a link how to do some top level OCL for derived properties?

Thanks in advance!

2 Answers

The use Of OCL with Stereotypes is massively underspecified. Zero mention in the OCL spec, only a hint of an example in the UML spec. The Pivot-based Eclipse OCL prototypes what is perhaps the only coherent implementation consist with the hint to give sensible type safe navigation using the base_XXX and extension_XXX names and multipicities. I doubt that any other tool does quite the same. I suspect that NoMagic used the traditional Classic Eclipse OCL where the inadequate OCL capabilities encourage many users to access the Eclipse MDT UML2 project Java API.

You might get some clues from https://help.eclipse.org/2020-03/topic/org.eclipse.ocl.doc/help/OCLExamplesforUML.html#OCLM2Constraints

If I well understand for a class stereotyped <<SystemGroup>> the derived attribute /size values the number of dependencies stereotyped <<collaborates>> starting from the class (whatever the type of the target), so something like :

context SystemGroup:: size: Integer
derive: self.clientDependency->select(v | v.stereotype.name = "collaborates")->size()

the number of Systems which are connected to the SystemGroup

does that means you also have the stereotype System and only the targets stereotyped <<System>> must be count ? If yes :

context SystemGroup:: size: Integer
derive: self.clientDependency->select(v | v.stereotype.name = "collaborates" and v.supplier.stereotype.name = "System")->size()

Warning /size is a derived attribute of the metaclass, so it is not available at the level of an application using instances of classes stereotyped <<SystemGroup>> for its implementation, are you sure this is what you want ?

P.S. to answer I used

Related