0

I am new to OCL, I am using papyrus on eclipse luna 4.4.2 I have a class diagram named CLIENT with the constraint {all attributes are out of scope} a second class named Customer with the constraint {all attributes are mandatory} and another class call Address having an attribute provenance with the constraint {provenance shall be mandatory}

How should I write the OCL constraint that suit the formal language? will also like to know how to verify the correctness of the syntax?

ReggieB
  • 8,100
  • 3
  • 38
  • 46
P.Proco
  • 1
  • 1
  • If you want to check the syntax of your OCL constraints you can use the evaluation console of the [Eclipse MDT/OCL](https://wiki.eclipse.org/OCL) or you try [Dresden OCLs](http://www.dresden-ocl.org/index.php/DresdenOCL) editor feature where you can load your model. But be aware that Dresden OCL is currently being without any active developer but very mature. – lschuetze Aug 15 '15 at 08:56
  • dear Reggie thx for your quick response, i am still waiting for a response on how to write the OCL constraint describe on each of the classes Client, Customer and Address. could someone help me please – P.Proco Aug 17 '15 at 22:57
  • You should specify what *out of scope* means. Furthermore, I am not sure you can iterate over every feature of a class since this is meta-programming. Are there lots of features per class? – lschuetze Aug 19 '15 at 06:09
  • Dear Ischuetze thx for your contribution. In the UML model, class CLIENT inherit from Class PERSON (is a special type of class Person) ; PERSON has several attributes such as "type and name". the constraint attach to Class Client is "All attributes are out of Scope except type and name" the explanation i can give is that "type and name" are the only attributes class CLIENT inherit from the superclass Person. waiting to hear from you!! – P.Proco Aug 19 '15 at 22:36

1 Answers1

0

In case of an collection it checks for non-emptiness and otherwise for an attribute it checks for non-null.

context Address inv: self.provenance->notEmpty()

For the other classes you have to do this for every attribute. If you want to do this for every attribute with one invariant you have to formulate them on the metamodel.

lschuetze
  • 1,218
  • 10
  • 25
  • sorry Ischuetze, What doing mean by meta hierarchy? are you referring to the name of the Class? waiting to hear from you – P.Proco Aug 19 '15 at 22:40