问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/32021672/how-to-write-ocl-contraint