Information Technology Reference
In-Depth Information
in <expression> construction.Forinstance,the capitalize
method is described in Listing 3.2.
1 context Attribute :: capitalize ():String
2 pre:name−>isNotEmpty()
3 post: let prem: String = name. substring(1 ,2).toUpper() in
4
result = prem.concat(name. substring(2, name. size ()))
Listing 3.2. OCL description of capitalize
In this expression, the prem expression is set and stands
in the resulting expression. The @pre operator allows
the specifier to specify the changes of attribute values
before and after a method call. For instance, if one wants
to specify a method that adds a suffix to an attribute name,
hewillwrite: context Attribute::addSuffix(String t)
post: name = name@pre + "_" + t . The expression
name@pre stands for the value of name before the call of
addSuffix that is at the pre-condition time.
One important aspect of OCL is navigating through
associations.Generally,theassociationnameisusedortherole
name,provided that the association is navigable.The resulting
type of such a navigation depends on the cardinality; if it is 1,
it is a single object; else, it is a collection. However, it is also
possible to add constraints on the end of the association; for
instance, to get a Sequence rather than a Set . To reach an
association class, or if the association has neither name nor
role, the specifier can use the name of the class in lowercase as
an implicit role. To navigate from an association class is like
navigating from a class.
OCL is a type-checked language allowing type hierarchies
and the associated operators to check for types. It also
introduces several base types and collections. Base types
are standard: Boolean , Integer , String , Real with their
natural operators. The abstract root of the collections is
Collection and has subclasses: Set , Bag , OrderedSet and
 
Search WWH ::




Custom Search