The Object Constraint Language: Getting Your Models Ready for MDA (2nd Edition)

In UML use cases, pre- and postconditions may be used. These may also be written using OCL. Because use cases are an informal way of stating requirements, and OCL is a formal language, some adjustments need to be made when the pre- and postconditions of use cases are defined using OCL expressions.

6.6.1 Preconditions and Postconditions

Although use cases can be considered to be operations defined on the complete system, you cannot identify the complete system as a type, because it is neither a class, an interface, a datatype, or a component. Therefore, the pre- and postconditions of a use case have no contextual type or contextual instance. As a consequence, the keyword self cannot be used.

Another consequence is that it is not clear which model elements may be referenced in the expression. Normally, all elements held by the contextual type may be used. Here, there is no contextual type. The model elements that may be used must be explicitly stated. This can be done by formalizing the types mentioned in the use case, e.g., Customer and Order , in an accompanying class diagram, and adding to the use case template a section called concerns with a list of variable declarations, e.g., newCustomer : Customer, newOrder : Order .

Yet another consequence is that you cannot write a context definition, as there is no contextual type to be referenced. The OCL expressions may be included in the use case at the position indicated by the use case template.

Категории