Object Constraint Language
The Object Constraint Language (OCL ) is a language that allows software architects necessary boundary conditions can define formally in the modeling of computer programs. The OCL is part of the globally established modeling language Unified Modeling Language ( UML) and is used, among other things, the textual specification of invariants of the class diagrams, sequence diagrams or of conditions in the formulation of pre-and postconditions for methods. The OCL syntax is based on the Smalltalk programming language. OCL has the UML version 1.1 part of the UML.
An important area of application of OCL is also in the model transformation. Here OCL is a central part of many transformation languages such as QVT or ATL.
The current version of the OCL is 2.3.1.
Constraints in OCL
It distinguishes seven types of constraints ( assertions ):
- Invariants must apply at any time for an instance or association.
- Preconditions / Postconditions must apply to the time at which the execution of the corresponding operation starts / ends.
- Initial and derived values represent conditions for the source and derived values dar.
- Definition: it can be defined attributes and operations that are not included in the model.
- Body definition of operations with IsQuery = true.
- Guards must apply when a state transition begins.
A constraint is always defined in the context of a context. This is any model entity, such as a class, a type, an interface or a component. We distinguish the type of context and the context instance. In the latter, the details of a constraint relate. For example, it can specify that for an instance of the class banana must not be larger than X is the value of the attribute curvature.
Object stands for a component of any system, these should be specified, defined or described in detail.
Constraint is a limitation or restriction; this can take maximum or minimum values , for example, the maximum number of simultaneous accesses to a database, or the maximum height of a building project.
Language is not here for a formal computer language, but rather for an applicable on every implementation less formal language.
OCL and UML
The OCL is designed as a complement to UML and is designed to make the modeling of software even more precisely. While in UML structures, processes and relations between objects are modeled, the boundary conditions of a model are specified in OCL addition. This may be for example, the restriction of an attribute to a value range, or to be maintained restrictions between objects. OCL expressions are consistent and can be processed by programs. They thus contribute to code generation, however, they do not change the model, but to monitor.
UML is more suitable for the development of a model, because diagrams are easier to understand than a textual representation of the model. OCL alone is not suitable for modeling software.
The following UML class diagram illustrates the OCL and can formulate various conditions in OCL:
- OCL reference OMG
- OCL Portal - The center for OCL related information