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 to be defined using OCL expressions. 3.8.1 Preconditions and Postconditions
Although use cases can be considered to be operations defined on the complete system, we cannot identify the complete system as a type, because it is not 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. In addition, 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. Therefore, 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 (for instance) concerns , with a list of variable declarations, e.g., newCustomer : Customer, newOrder : Order . Yet another consequence is that we cannot write a context definition, as there is no contextual type to be referenced. This is not a problem. The OCL expressions may be directly included in the use case at the position indicated by the use case template. The following example illustrates a use case for the R&L system. It describes how customer cards are upgraded and how invalid cards are removed from the system. Because not all information about the attributes and operations in the system could be included in Figure 2-1, the CustomerCard class ”with all attributes used in the following use case ”is reprinted in Figure 3-12. [View full width]
[View full width] Use case title : Check customer cards for loyalty program Summary : On a regular basis the cards of all participants in a loyalty program areFigure 3-12. Class CustomerCard , with all its attributes and operations
|