0

Is OCL meant to be used in combination with a composite structure diagram?

Or does it not make sense? If it makes sense, could someone give a quick example for a possible OCL constraint, e.g. based on this example diagram source ?

enter image description here

langlauf.io
  • 3,009
  • 2
  • 28
  • 45
  • 2
    OCL doesn't work with diagrams, it is used on Elements. Maybe you should explain what you are trying to achieve. – Geert Bellekens Oct 30 '15 at 14:59
  • @GeertBellekens If we take the composite structure diagram linked above, I would like to constrain for example: "If the MainWindow's title is "My XOR App", then there is either an OkButton or a CancelButton (exclusive or). – langlauf.io Oct 30 '15 at 15:40
  • I don't see why you shouldn't be able to post such image, it looks like fair use to me (if such diagram can be even copyrighted) – Peter Uhnak Oct 30 '15 at 15:53

1 Answers1

2

UML specifically mentions such situation (section 7.6. of specs)

enter image description here

Constraints themselves can be attached to any kind of UML Element, or in fact a collection of Elements.

enter image description here

And finally:

7.2.1

The root concepts of Element and Relationship provide the basis for all other modeling concepts in UML.

Which means that you can add constraint to anything.

Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
  • And if the diagram was a composite structure diagram such as the one I linked in my question? @GeertBellekens points out in his comment that OCL works with elements (not diagrams). This makes me think that you can write OCL constraints for all kinds of models / model diagrams. What do you think? – langlauf.io Oct 30 '15 at 15:52
  • 1
    You should **define** the OCL constraints on the classes. They are then **validated** on the instances. – Geert Bellekens Oct 30 '15 at 15:59