2

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!

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
Jannecee
  • 21
  • 1

2 Answers2

1

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

Ed Willink
  • 1,205
  • 7
  • 8
  • To me OCL is just an academic thing. Would be nice, but there's no support except for some academic projects (IIRC University of Dresden has something). EA claims (haha!) to support OCL but even the simplest code piece is rejected to be syntactically incorrect. But of course there's a drop to to state that a constraint is written in OCL. Sales feature... – qwerty_so Aug 26 '20 at 18:30
0

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

bruno
  • 32,421
  • 7
  • 25
  • 37
  • Thanks! From the functionality that's exactly what I was looking for. Anyhow your last question or the warning is really important too because that's not what I want. I thought that I could use this attribute on instance level. I want: instead of a regular block, i want a stereotyped block `<>` which always has a property which describes the size of the group by counting the `<>` relations. Could you explain how I can do that? My only idea would be to use a customization (and don't create the attribute on the stereotype?!). Thank you so much in advance! – Jannecee Aug 28 '20 at 08:24
  • @Jannecee So you need to have *size* defined on the *classes* (may stereotyped ` <>`) rather than on the *metaclass*, note in that case its value is a constant, and it can be supported by a constant attribute or an operation returning a constant. I do not know the modeler you use so I cannot know if it can automatize its generation – bruno Aug 28 '20 at 10:26
  • I'm using the Cameo Systems Modeler from No Magic with the newest version installed. So my thought was that I create a profile/DSL which is than used to develop these specific systems... If I create the size on the instance-level it's only for that specific instance right? Or do I've got sth wrong? My idea was that later - in an actual model (which applies the profile I created) - you have the stereotyped block `<>` which has a predefined value for the size that derives from the number of `<>` relationships (just like you've got it right earlier). – Jannecee Aug 29 '20 at 15:04
  • @Jannecee `If I create the size on the instance-level it's only for that specific instance right?`yes, this is why it is better to have the attribute/operation at class-level (*static* in UML / C++ / Java / ...). For the rest you have to look at the documentation of your modeler, again I do not know it / the features it offers – bruno Aug 29 '20 at 16:05