Object Constraint Language –OCL

 

About OCL:-

The Object Constraint Language (OCL) is an expression language that describes constraints on object-oriented languages and other modelling artifacts. A constraint can be seen as a restriction on a model or a system. OCL is part of Unified Modeling Language (UML) and it plays an important role in the analysis phase of the software lifecycle.

Object Constraint Language (OCL), is a formal language

to express side effect-free constraints. Users of the Unified Modeling Language and other

languages can use OCL to specify constraints and other expressions attached to their models.

 

OCL is the expression language for the Unified Modeling Language (UML). To understand OCL, the component parts of this statement should be examined. Thus, OCL has the characteristics of an expression language, a modeling language and a formal language.

 

OCL is a pure expression language. Therefore, an OCL expression is guaranteed to be without side effect. It cannot change anything in the model. This means that the state of the system will never change because of an OCL expression, even though an OCL expression can be used to specify such a state change (e.g., in a post-condition). All values for all objects, including all links, will not change. Whenever an OCL expression is evaluated, it simply delivers a value.

OCL is a modeling language, not a programming language. It is not possible to write program logic or flow-control in OCL. You especially cannot invoke processes or activate non-query operations within OCL. Because OCL is a modeling language in the first place, not everything in it is promised to be directly executable.

As a modeling language, all implementation issues are out of scope and cannot be expressed in OCL. Each OCL expression is conceptually atomic. The state of the objects in the system cannot change during evaluation.

OCL is a formal language where all constructs have a formally defined meaning. The specification of OCL is part of the UML specification.OCL is not intended to replace existing formal languages, like VDM, Z etc

Why a formal language?

In object-oriented modeling, a graphical model, like a class model, is not enough for a precise and unambiguous specification. There is a need to describe additional constraints about the objects in the model. Such constraints are often described in natural language. Practice has shown that this will always result in ambiguities. To write unambiguous constraints so-called formal languages have been developed.

Selecting OCL over other Formal Languages.

                                    Traditional formal languages are useable to persons with a string mathematical background, but difficult to use for the average business or system modeler. OCL has been developed to fill this gap. OCL is a formal language, which remains easy to read and write.

In object-oriented modeling a graphical model, like a class model, is not enough for a precise and

unambiguous specification. There is a need to describe additional constraints about the objects in

the model. Such constraints are often described in natural language. Practice has shown that this

will always result in ambiguities. In order to write unambiguous constraints, so-called formal

languages have been developed. The disadvantage of traditional formal languages is that they are useable to persons with a string mathematical background, but difficult for the average business or system modeler to use.

 

OCL has been developed to fill this gap. It is a formal language that remains easy to read and

write. It has been developed as a business modeling language within the IBM Insurance division,

 

OCL is a pure expression language. Therefore, an OCL expression is guaranteed to be without

side effect; it cannot change anything in the model. This means that the state of the system will

never change because of an OCL expression, even though an OCL expression can be used to

specify a state change, e.g. in a post-condition. All values for all objects, including all links, will

not change. Whenever an OCL expression is evaluated, it simply delivers a value.

 

OCL is not a programming language, so it is not possible to write program logic or flow control

in OCL. You cannot invoke processes or activate non-query operations within OCL. Because

OCL is a modeling language in the first place, not everything in it is promised to be directly

executable.

 

OCL is a typed language, so each OCL expression has a type. In a correct OCL expression all

types used must be type conformant. For example, you cannot compare an Integer with a String.

Types within OCL can be any kind of Classifier within UML.

 

As a modeling language, all implementation issues are out of scope and cannot be expressed in

OCL. Each OCL expression is conceptually atomic. The state of the objects in the system cannot

change during evaluation.

 

Applications of OCL

 

OCL can be used for a number of different purposes:

To specify invariants on classes and types in the class model

To specify type invariant for Stereotypes

To describe pre- and post conditions on Operations and Methods

To describe Guards

As a navigation language

To specify constraints on operations

 

 

History of the Object Constraint Language

In 1996, the OA&D Domain task force at the Object Management Group (OMG) issued a request for proposals on Object Analysis and Design. IBM and ObjecTime Limited jointly submitted a proposal in January 1997. An important aspect of this proposal was the inclusion of the Object Constraint Language, or OCL.

During 1997 IBM and ObjecTime have collaborated with the Unified Modeling Language (UML) partners and merged parts of their proposal with the UML proposal. This has resulted in the current UML 1.1 proposal.

IBM's primary contribution to UML 1.1 is OCL. OCL was developed by Jos Warmer as a language for business modelling within IBM, derived from the Syntropy method of Steve Cook and John Daniels. It is used within UML both to help formalize the semantics of the language itself, and to provide a facility for UML users to express precise constraints on the structure of models.

 

For a Sample OCL visit this link:-

http://www.csci.csusb.edu/dick/samples/ocl.html

 

and For a detailed studying of OCL visit this link:-

www.jeckle.de/files/UML1_2/apndxb.pdf

 

 

Submitted by: Sajayasree K K,

          ME(CSE).

 

          saju@csa.iisc.ernet.in