Attribute Multiplicity

Help
Dina
2012-02-06
2013-04-29
  • Dina
    Dina
    2012-02-06

    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

          

     
  • Lars Hamann
    Lars Hamann
    2012-02-07

    Hi!

    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()
    

    Best regards!
    Lars