Ingeniería del Software
Universidad de MurciaGrupos de InvestigaciónInvestigación

Fotografía de la Facultad de Informática

b-grana.gif (931 bytes)Home
b-grana.gif (931 bytes)OCL
b-grana.gif (931 bytes)Tools

b-grana.gif (931 bytes)ModelRun
b-grana.gif (931 bytes)OCL Compiler (Cybernetic)
b-grana.gif (931 bytes)OCL Compiler (Dresden)
b-grana.gif (931 bytes)OCL Checker
b-grana.gif (931 bytes)USE
b-grana.gif (931 bytes)Others

b-grana.gif (931 bytes)OCL Resources
b-grana.gif (931 bytes)References
b-grana.gif (931 bytes)Updates
b-grana.gif (931 bytes)About


The Object Constraint Language (OCL)

OCL was developed by Jos Warmer as a business modeling language within IBM and derived from Steve Cook’s and John Daniels’s Syntropy method (Cook and Daniels, 1944). In 1996 the OA&D Domain task force at OMG issued a request for proposals on Object Analysis and Design. In January 1997, IBM and ObjectTime Limited received the proposal, one important aspect of which was the introduction of OCL. During 1997 IBM and ObjectTime collaborated with the UML project. OCL was IBM’s first contribution to UML 1.1.

The recent success of UML (OMG, 1999; OMG, 2001) has also led to increased popularity of OCL (Warmer and Kleppe, 1999b), especially from the 1.1 version of UML up onwards, when this language is used in the UML standard. The OMG is currently working on the new version OCL2.0, where an important new aspect is a well defined meta model, which makes it easier to develop OCL tools.

OCL is currently used in the definition of other OMG standards. In the specification of MOF (OMG, 2000a), for example, OCL is used to define the more complex concepts of the MOF model. It is likewise used in the specification of XMI (OMG, 2000b) to specify the manner in which a model is transformed into a document.

OCL is also used in software development processes to improve the expressiveness of certain artefacts in the analysis and design phases. Another use is to provide support to certain UML extensibility mechanisms. In UML models, constraints written in OCL can be used to supply complementary information, at a conceptual level, to achieve higher precision and accuracy within the model. In particular, OCL can be used to (OMG, 2001):

  • Specify invariants on classes and types in the class model
  • Specify type invariant for Stereotypes
  • Describe pre- and post conditions on Operations and Methods
  • Describe Guards
  • Specify constraints on operations
  • As a navigation language

The main characteristics of OCL

OCL is a semiformal language that can be used to express constraints on a variety of software artifacts. UML users and those of other modeling languages can use OCL to specify constraints and other expressions in their models, as well as to describe business rules explicitly (Gottesdiener, 1999). The main characteristics of OCL are:

  • It is a pure expression language. It guarantees that an OCL expression will have no side effects. In other words, the state of the system will never change as a result of an OCL expression.

  • OCL assists in formalizing the language and provides a precise, easy way of expressing constraints in the structure of the models.

  • OCL is not a programming language; therefore, it is not possible to write program logic or flow control in OCL.

  • OCL is a typed language and hence every expression has a type. For an expression to be correct, all the types must be in agreement.

  • Each OCL expression is attached to a model and describes specific characteristics of the model.

Examples of the types of expressions that we can write with OCL are invariants, preconditions, postconditions, guards, navigation expressions, etc. Each OCL expression is attached to a model and describes specific characteristics of the model.

An example in OCL

The following diagram of UML classes serves as an example for kinds of constraints.

In UML, we use OCL to write the constraints. Each constraint is defined in the context of a specific instance of the class indicated. The most common kinds of constraints are: invariants, preconditions and postconditions. An invariant constraint attached to a class means that all instances of the class must satisfy the constraint. Both preconditions and postconditions are constraints attached to operations or methods (Warmer and Kleppe, 1999a). On the other hand, the reserved word self is used to refer to the instance in the actual context. The OCL constraints attached to the diagram in Figure 1 are given below:

  1. The number of staff in a company must be higher than 50.

    context Company

    inv: self.numberOfEmployees > 50

  2. The salary of a person must be higher than the minimum salary - fixed at US. $420.7.

    context Person::income(d:date): Real

    post: result > 420.7

  3. When a company contracts an individual, he or she forms part of the staff.

    context Company::contract(p:person)

    pre contractPre: employee->excludes(p)
    post contractPost: employee->includes(p)

  4. The set of all married members of staff must not be empty.

    context Company

    inv: self.employee->select(isMarried)->notEmpty

  5. The ages of all the members of staff must be between 18 and 65

    context Company

    Inv: self.employee->forAll(r:Person | r.age >=18 and r.age <= 65)

For more information about OCL, see references (OMG, 1999; OMG, 2001; Rational, 2000) and the following websites: OCL Home http://www.klasse.nl/ocl; IBM,http://www3.ibm.com/software/ad/library/standards/ocl.html; Rational, http://www.rational.com; OMG , http://www.omg.org./uml .

[Top]

Estructura de la Universidad de Murcia. Org. de Gobierno, Centros, Departamentos, Servicios, Escuelas, Vicerrectorados, etcInformación General. Publicaciones, Cursos, Becas, Información Internacional, etc.Estudios de primer y segundo ciclo, Doctorado, Títulos propios...Alumnos. Información de interés para estudiantes y titulados de la Universidad de MurciaInvestigación. Convocatorias, Tercer Ciclo, Servicios de Investigación, OTRI...Personal de Administración y Servicios, Personal de Docencia e Investigación. Infosecundaria. Información dirigida a los Centros de Enseñanza SecundariaSabio. Consulta a Bases de Datos de Becas, Empleo, Bolsa de Libros, Bolsa de PisosBiblioteca. Consulta a catálogos y Bases de Datos Bibliográficas, Servicios, Reglamentos... Servicio de Informática. Servicios y Proyectos del Servicio de Informática de la UMU.
Novedades web.Búsquedas en el web de la Universidad de Murcia.Escríbanos. Envie sus comentarios, sugerencias o consultas informativas.Directorio. Servicio de directorio, e-mails, teléfonos, etc.Prensa. Noticias de prensa actualizadas diariamente.Ayuda. Información sobre la estructura de este web.Canal Universitario. Informativo Universitario emitido diariamente en Televisión Murciana.