A.1. Building OCL ExpressionsFigure A-2 shows a class diagram with a few OCL expressions, including:
Figure A-2. Example OCL constraints of varying complexity
OCL expressions consist of model elements, constants, and operators. Model elements include class attributes, operations, and members though association. The OCL expressions in Figure A-2 use the model elements baseCost, totalCost, and getTaxRate( ). (Later sections contain OCL expressions with members through association.) Constants are unchanging values of one of the predefined OCL types. In Figure A-2, constants include 0.0 of type Real and 'Unpaid' of type String. Operators combine model elements and constants to form an expression. In Figure A-2, operators include <>, +, and =. The following sections discuss the basics of OCL types and operators and then show how to combine these into expressions you can use in your UML models. |