Sparx Systems Forum
Enterprise Architect => Uml Process => Topic started by: William McKenzie on August 03, 2012, 08:40:45 am
-
This is a question for any OCL experts that might be out there. If I am adding a constraint directly to an attribute (not its class) does self still refer to the class? Given class==Person and attribute==Name, suppose I want to write the constraint that the string length of Name must be less than 40.
Most of the OCL examples I've seen say something like this:
this.Name->length() < 40.
That would make sense if the constraint was written on the class. But if I write on the attribute, do I simply write:
this->length() < 40, or even just length() < 40
Just wondering. If it's just for documentation, it doesn't really matter, as long as I can read it and understand it. But for model validation, or transformation I'd like it to be syntactically correct.
-
The reason why most OCL examples will use this.Name etc. is because UML allows for a Namespace (which a class is) to own a rule, it doesn't allow for attributes owning rules.
You could always write it as length() < 40 on the attribute in EA and then transform that to add the this.Name before whatever is going to read it.
-
Thanks, Simon. Supplementary question: Are there any of the built-in transforms that would take a constraint like that and turn it into a column-length specification for a physical database model? Or is one better off leaving that sort of thing out of the domain model and just putting it into database model?