-
Notifications
You must be signed in to change notification settings - Fork 0
Attributes
Now we focus on the attributes in our example class definition:
class Accessible Shaft Level, ASLEV
attributes
Floor : Level Name {I, R3}
Shaft : Shaft ID {I, R3}
Bank : Bank Name {R3c}
Stop requested : Boolean
--
There can be a lot going on here, so the grammar is a bit more involved:
// Attributes
attr_block = attr_header attribute+ // A set of attributes
attr_header = "attributes" EOL*
attribute = INDENT derived? attr_name (' : ' type_name)? (SP attr_tags)? default_value? EOL*
default_value = SP '=' SP dval
derived = '/'
attr_name = icaps_name
type_name = icaps_name
attr_tags = '{' attr_tag (',' SP attr_tag )* '}' // {I, I2, R29c} for example
attr_tag = itag / rtag
itag = '*'? 'I' ordinal? // Identifier number, both I and I1 mean the same thing, optional super identifier * symbol
rtag = 'O'? 'R' ordinal 'c'? // Relationship number and optional c constraint signifier
The attr_block starts off with the unindented keyword attributes just below the class name line.
Then each attribute definition is indented. The attributes are in no particular sequence, as far as the model
itself is concerned, but Flatland will draw them top to bottom in that order.
A final unindented -- separator
The first attribute line in the example is:
Floor : Level Name {I, R3}
Here we have the attribute name, Floor which can be a multi word name, delimited by spaces, and the first letter of
the first word must be upper case. By convention, only the initial word should start with an uppercase letter.
But the grammar does not prevent you from using uppercase wherever you like in an attribute name.
Every attribute is typed and the type name appears after the colon which is surrounded by a single space on each
side. Here the name is Level Name.
If an attribute has special properties, these are tagged between {} braces after the type name. There must be one
space before the opening {.
The I tag indicates that this attribute is part of the primary identifier.
The R3 tag indicates that this is a referential attribute (foreign key in relational terminology). It means
that any value assigned to this attribute must match the value of a corresponding attribute of the same type
defined on the other side of the R3 relationship.
The Shlaer-Mellor methodology defines clear rules regarding how identifier and referential attributes are defined and these are appropriated from relational theory.
A c might appear after a tagged relationship name. It means that there is a further constraint on any value
that may be assigned to the referential attribute. That constraint should be defined in the model's attribute
description which will be outside the xcm file. For now anyway.
Bank : Bank Name {R3c}
We can take another example class from the same elevator model so that we can see a usage of the ordinal tag.
class Floor
attributes
Name : Level Name {I}
Height : Distance {I2, OR7}
--
Floors are ordered by height so an ordinal relationship, OR7 is defined. As far as the tag is concerned it
is simply a matter of allowing an O character (o, not zero) as part of the relationship name.
A derived attribute is designated using the UML / symbol in front of the attribute name with no space
between the two. It designates an attribute whose value is directly computed from other attributes in the same
or different classes.
A default value may be specified for an attribute. The single space on either side of the equal sign is required.
Stop requested : Boolean = false
Copyright 2023-2026 © Leon Starr under MIT Open Source License