I have some questions regarding the tool modeling.
Q1: Are the class attributes optional by default or not? If not, How can I indicate that they are optional?
For example, I want to model class Book which has a "year" as a normal attribute, an "ISBN" as an optional attribute, and another one called GS1 which is optional; it doesn't exist except if the ISBN number and satisfies the condition that the "year" is greater than or equal 2007.
Q2: I have a class book and I want to say that it is either edited by an Editor or authored by an author but it can't be both (i.e. an XOR relationship). How can I write this type of constraint using OCL in your tool?
Thanks a lot
A1: Attributes are optional by default. To make them mandantory you need to specify an invariant.
context Book inv: self.year.isDefined()
A2: Given the association ends "author" and "editor" you can write:
context Book inv authorExcludesEditor: self.author.isDefined() implies self.editor.isUndefined()
Log in to post a comment.