Object Constraint Language

The Object Constraint Language (OCL) is a declarative language describing rules applying to Unified Modeling Language (UML) models developed at IBM and is now part of the UML standard. Initially, OCL was merely a formal specification language extension for UML.[1] OCL may now be used with any Meta-Object Facility (MOF) Object Management Group (OMG) meta-model, including UML.[2] The Object Constraint Language is a precise text language that provides constraint and object query expressions on any MOF model or meta-model that cannot otherwise be expressed by diagrammatic notation. OCL is a key component of the new OMG standard recommendation for transforming models, the Queries/Views/Transformations (QVT) specification.

Description

OCL is a descendant of Syntropy, a second-generation object-oriented analysis and design method. The OCL 1.4 definition specified a constraint language. In OCL 2.0, the definition has been extended to include general object query language definitions.

OCL statements are constructed in four parts:

  1. a context that defines the limited situation in which the statement is valid
  2. a property that represents some characteristics of the context (e.g., if the context is a class, a property might be an attribute)
  3. an operation (e.g., arithmetic, set-oriented) that manipulates or qualifies a property, and
  4. keywords (e.g., if, then, else, and, or, not, implies) that are used to specify conditional expressions.

Relation

OCL and UML

OCL supplements UML by providing expressions that have neither the ambiguities of natural language nor the inherent difficulty of using complex mathematics. OCL is also a navigation language for graph-based models.

OCL and MOF

OCL makes a Meta-Object Facility model more precise by associating assertions with its meta-elements.

OCL and QVT

Of particular importance to Model Driven Engineering (MDE) or model-driven architecture is the notion of Model transformation. The OMG has defined a specific standard for model transformation called MOF/QVT or in short QVT. Several model transformation languages like GReAT, VIATRA, or Tefkat are presently available, with different levels of compliance with the QVT standard. Many of these languages are built on top of OCL, which is the main part of the QVT-compliance.

Alternatives

Being a rule-based validation language, Schematron may be considered an alternative to OCL. However Schematron works for Extensible Markup Language (XML) trees while OCL makes it possible to navigate MOF-based models and meta-models (i.e. XML Metadata Interchange (XMI) trees). In other words, OCL relates to UML or MOF similarly to how Schematron relates to XML. (Note that Schematron uses XPath to navigate inside the XML trees.)
Being a model specification language permitting designers to decorate a model or a meta-model with side-effect-free annotations, OCL could be replaced by languages like Alloy. Automated OCL generation is possible through Natural Language like NL2OCL.[3]

Example

Constraints

  1. The age of a person is not negative.
  2. A person is younger than its parents.
  3. After a birthday, a person becomes one year older.
  4. A Person has 2 parents at max.
  5. After somebody got a child, his/her child-set is nor empty, and it is lager than before.
  6. Only an adult can be owner of a car.
  7. The first registration of a car can not be before it is built.
  8. Every Person, that has a car has at least one car which is younger than the Person.
  9. Nobody can be his/her own parent.
  10. There's at least one Person which owns a car.

OCL Constraints

  1. context Person inv: self.age >=0
  2. context Person inv: self.parents->forAll(e|e.age>self.age)
  3. context Person::hasBirthday() post: self.age=self.age@pre+1
  4. context Person inv: self.parents->size()<=2
  5. context Person::getsChild() post: self.childs->notEmpty() and self.childs->size() > self.childs@pre->size()
  6. context Person inv: self.age<18 implies self.cars->isEmpty()
  7. context Auto inv: self.registration>=self.constructionYear
  8. context Person inv: self.cars->notEmpty() implies self.cars->exists( a | Calendar.YEAR - a.constructionYear < self.age)
  9. context Person inv: self.parents->excludes(self)
  10. context Person inv: Person.allInstances()->exists(p | p.cars->size() > 0)

See also

References

  1. Object Management Group (OMG); Object Constraint Language Specification, Chapter 7 of OMG Unified Modeling Language Specification, Version 1.3, March 2000 (first edition)
  2. Object Management Group (OMG); Object Constraint Language OMG Available Specification Version 2.0, May 2006
  3. Imran Sarwar Bajwa (October 2010). "OCL Constraints Generation from Natural Language Specification, 2010". IEEE.

This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.