|
|
|
|
|
|
|
|
|
|
|
|
Although the UML contains a lot of diagram elements, e.g. class diagrams,
activity diagrams, state charts and more, these diagrams cannot be used to
specify calculations on the objects of your software systems.
Nevertheless, in any non trivial software system there is a huge amount of information of this type that needs to be clearly understood by all people involved in the creation of the system, be they business analysts, designers, coders, testers or technical writers. For example, you might need to capture the information, that an applicant for an insurance must be at least 18 years old. Traditionally, you would add some notes to your class diagrams or you would extend an UML Use Case and add a textual description of this requirement: An applicant must be at least 18 years old. But this approach has a number of drawbacks:
Avoiding AmbiguityBeing a formal language, the expression becomes unambiguous. The knowledge gathered by the business analysts can be captured without loss.Ensuring ConsistencyThe business knowledge that is expressed as OCL expressions is stored where it should be stored: in your UML model, together with all the other elements and definitions that form the foundation of your software system.Complete checking of the expression is possible. Thus errors are detected immediately during editing the expression and the danger of errors is greatly reduced. If an expression becomes outdated because of changes in the model, this is also indicated. The consistency of the OCL expressions and the rest of the model is thus ensured. Enabling Additional ProcessingSince the OCL expressions are maintained as dedicated model elements, it is possible to extract and process these elements. E.g. it is possible to generate reports of all specified constraints as a reference for testers and technical writers.Generating Code From OCL ExpressionsIf you are using an MDA-like approach, the code generators can use the OCL expressions to automatically create assert-statements or method implementations for get-methods. Since the abstraction level of OCL is significantly higher than with traditional object oriented programming languages, this approach results in a reduction of the error rate. In addition, this allows reuse of the captured business rules on all supported target platforms.Discover sloppy specificationsIn a sense, the most important benefit of using OCL is that thinking about a precise specification of the systems requirements helps you to gain a better and more complete understanding of the system. This, in turn, makes your implementation phase more effective. |