Book a Demo

Author Topic: Constraints on attributes.  (Read 14461 times)

William McKenzie

  • EA User
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Constraints on attributes.
« 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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Constraints on attributes.
« Reply #1 on: August 03, 2012, 10:08:24 am »
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.

William McKenzie

  • EA User
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Re: Constraints on attributes.
« Reply #2 on: August 04, 2012, 12:39:18 am »
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?