Object Constraint Language: Difference between revisions

From HandWiki
imported>Wikisleeper
change
 
link
 
Line 1: Line 1:
{{Short description|Declarative language}}
{{Short description|Declarative language}}
{{Update|date=April 2018}}


The '''Object Constraint Language''' ('''OCL''') is a declarative language describing rules applying to [[Unified Modeling Language]] (UML) models developed at [[Company:IBM|IBM]] and is now part of the UML standard. Initially, OCL was merely a formal specification language extension for UML.<ref>Object Management Group (OMG); ''Object Constraint Language Specification'', Chapter 7 of ''OMG Unified Modeling Language Specification'', Version 1.3, March 2000 (first edition)</ref> OCL may now be used with any [[Organization:Meta-Object Facility|Meta-Object Facility]] (MOF) [[Organization:Object Management Group|Object Management Group]] (OMG) [[Metamodeling|meta-model]], including UML.<ref>Object Management Group (OMG); ''Object Constraint Language OMG Available Specification Version 2.0'', May 2006</ref> 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.
The '''Object Constraint Language''' ('''OCL''') is a declarative language describing rules applying to [[Unified Modeling Language]] (UML) models developed at [[Company:IBM|IBM]] and is now part of the UML standard. Initially, OCL was merely a formal specification language extension for UML.<ref>Object Management Group (OMG); ''Object Constraint Language Specification'', Chapter 7 of ''OMG Unified Modeling Language Specification'', Version 1.3, March 2000 (first edition)</ref> OCL may now be used with any [[Organization:Meta-Object Facility|Meta-Object Facility]] (MOF) [[Organization:Object Management Group|Object Management Group]] (OMG) meta-model, including UML.<ref>Object Management Group (OMG); ''Object Constraint Language OMG Available Specification Version 2.0'', May 2006</ref> 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 ==
== 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 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.<ref name="FOLDOC">{{foldoc|Object+Constraint+Language}}</ref>


OCL statements are constructed in four parts:
OCL statements are constructed in four parts:
Line 15: Line 16:
==Relation==
==Relation==
=== OCL and UML ===
=== OCL and UML ===
OCL supplements [[Unified Modeling Language|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 supplements UML by providing expressions that have neither the ambiguities of natural language nor the inherent difficulty of using complex mathematics.<ref name="FOLDOC" /> OCL is also a navigation language for graph-based models.


=== OCL and MOF ===
=== OCL and MOF ===
Line 24: Line 25:


== Alternatives ==
== Alternatives ==
Being a rule-based validation language, [[Schematron]] may be considered an alternative to OCL. However Schematron works for Extensible Markup Language [[XML tree|(XML) tree]]s while OCL makes it possible to navigate [[Organization:Meta-Object Facility|MOF]]-based models and meta-models (i.e. XML Metadata Interchange ([[XML Metadata Interchange|XMI]]) trees). In other words, OCL relates to [[Unified Modeling Language|UML]] or MOF similarly to how Schematron relates to [[XML]]. (Note that Schematron uses [[XPath]] to navigate inside the XML trees.)<br>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 in principle possible from natural language.<ref name="NL2OCL">{{cite journal| author=Imran Sarwar Bajwa|title=OCL Constraints Generation from Natural Language Specification, 2010|publisher =IEEE|date=October 2010|doi=10.1109/EDOC.2010.33|s2cid=7495256}}</ref>
Being a rule-based validation language, [[Schematron]] may be considered an alternative to OCL. However Schematron works for Extensible Markup Language [[XML tree|(XML) tree]]s while OCL makes it possible to navigate [[Organization:Meta-Object Facility|MOF]]-based models and meta-models (i.e. XML Metadata Interchange ([[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.)<br>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 in principle possible from natural language.<ref name="NL2OCL">{{cite journal| author=Imran Sarwar Bajwa|title=OCL Constraints Generation from Natural Language Specification, 2010|publisher =IEEE|date=October 2010|doi=10.1109/EDOC.2010.33|s2cid=7495256}}</ref>
 
== Examples ==


{| class="wikitable"
{| class="wikitable"
Line 65: Line 68:
== Extensions ==
== Extensions ==


Eclipse OCL <ref>{{cite web | url=https://projects.eclipse.org/projects/modeling.mdt.ocl | title=Eclipse OCL™ (Object Constraint Language) | date=31 January 2013 }}</ref> extends Standard OCL with additional operators and a type for Maps. AgileUML extends Standard OCL with Map and Function types.<ref>{{cite book | chapter-url=https://link.springer.com/chapter/10.1007/978-3-030-89247-0_8 | doi=10.1007/978-3-030-89247-0_8 | chapter=Extending OCL with Map and Function Types | title=Fundamentals of Software Engineering | series=Lecture Notes in Computer Science | year=2021 | last1=Lano | first1=Kevin | last2=Kolahdouz-Rahimi | first2=Shekoufeh | volume=12818 | pages=108–123 | isbn=978-3-030-89246-3 | s2cid=239029860 }}</ref> These extensions are consistent with the map and function types present in modern programming languages such as Python and Swift.
Eclipse OCL<ref>{{cite web | url=https://projects.eclipse.org/projects/modeling.mdt.ocl | title=Eclipse OCL™ (Object Constraint Language) | date=31 January 2013 }}</ref> extends Standard OCL with additional operators and a type for Maps. AgileUML extends Standard OCL with Map and Function types.<ref>{{cite book | chapter-url=https://link.springer.com/chapter/10.1007/978-3-030-89247-0_8 | doi=10.1007/978-3-030-89247-0_8 | chapter=Extending OCL with Map and Function Types | title=Fundamentals of Software Engineering | series=Lecture Notes in Computer Science | year=2021 | last1=Lano | first1=Kevin | last2=Kolahdouz-Rahimi | first2=Shekoufeh | volume=12818 | pages=108–123 | isbn=978-3-030-89246-3 | s2cid=239029860 }}</ref> These extensions are consistent with the map and function types present in modern programming languages such as Python and Swift.


== See also ==
== See also ==
Line 72: Line 75:
* Domain Specific Language  (DSL)
* Domain Specific Language  (DSL)
* Domain-specific modelling (DSM)
* Domain-specific modelling (DSM)
* [[Software:Eclipse|Eclipse]] [https://web.archive.org/web/20060407092135/http://www.eclipse.org/gmt/ GMT Project]
* [[Astronomy:Eclipse|Eclipse]] [https://web.archive.org/web/20060407092135/http://www.eclipse.org/gmt/ GMT Project]
* [[Gello Expression Language]]
* [[Gello Expression Language]]
* [[Glossary of Unified Modeling Language terms]]
* [[Glossary of Unified Modeling Language terms]]
* Intentional Programming (IP)
* List of UML tools
* List of UML tools
* Meta-modeling
* Meta-modeling
Line 104: Line 106:
* [http://www-st.inf.tu-dresden.de/ocl/ OCL Portal - The center for OCL related information]
* [http://www-st.inf.tu-dresden.de/ocl/ OCL Portal - The center for OCL related information]
* [http://www.csci.csusb.edu/dick/samples/ocl.html OCL page of Computer Science Dept. of CSUSB] (brief OCL 2.0 syntax)
* [http://www.csci.csusb.edu/dick/samples/ocl.html OCL page of Computer Science Dept. of CSUSB] (brief OCL 2.0 syntax)
* [http://octopus.sourceforge.net/ Octopus: OCL Tool for Precise Uml Specifications] (OCL checker)
* [https://octopus.sourceforge.net/ Octopus: OCL Tool for Precise Uml Specifications] (OCL checker)
* [http://www.dresden-ocl.org/index.php/DresdenOCL Dresden OCL Toolkit] (OCL Toolkit, various OCL related publications)
* {{usurped|1=[https://archive.today/20121225102952/http://www.dresden-ocl.org/index.php/DresdenOCL Dresden OCL Toolkit]}} (OCL Toolkit, various OCL related publications)
* [http://www.brucker.ch/projects/hol-ocl/ HOL-OCL] (An interactive theorem proof environment for OCL, various OCL related publications)
* [http://www.brucker.ch/projects/hol-ocl/ HOL-OCL] (An interactive theorem proof environment for OCL, various OCL related publications)
* [https://web.archive.org/web/20060220003552/http://www.parlezuml.com/tutorials/umlforjava/java_ocl.pdf OCL for Java tutorial on ParlezUML]  
* [https://web.archive.org/web/20060220003552/http://www.parlezuml.com/tutorials/umlforjava/java_ocl.pdf OCL for Java tutorial on ParlezUML]  
* [http://www.eclipse.org/articles/article.php?file=Article-EMF-Codegen-with-OCL/index.html Article on using EMF's OCL in Java code]
* [http://www.eclipse.org/articles/article.php?file=Article-EMF-Codegen-with-OCL/index.html Article on using EMF's OCL in Java code]
* [https://web.archive.org/web/20060831031409/http://www.cetus-links.org/oo_uml.html UML link page on cetus-links.org]
* [https://web.archive.org/web/20060831031409/http://www.cetus-links.org/oo_uml.html UML link page on cetus-links.org]
* [http://sourceforge.net/projects/useocl/ USE (UML-based Specification Environment)] (OCL Tool for model validation, various OCL related publications)
* [https://sourceforge.net/projects/useocl/ USE (UML-based Specification Environment)] (OCL Tool for model validation, various OCL related publications)
* [http://modeling-languages.com/ocl-tutorial/ OCL tutorial]
* [http://modeling-languages.com/ocl-tutorial/ OCL tutorial]
* [http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5630350/ NL2OCL] (OCL Tool for invariant generation from NL)
* [https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5630350/ NL2OCL] (OCL Tool for invariant generation from NL)


{{ISO standards}}
{{ISO standards}}

Latest revision as of 07:29, 14 April 2026

Short description: Declarative 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.[3]

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.[3] 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 in principle possible from natural language.[4]

Examples

Examples
Constraint OCL Equivalent
The age of a person is not negative. context Person inv: self.age >=0
A person is younger than its parents. context Person inv: self.parents->forAll(p|p.age>self.age)
After a birthday, a person becomes one year older. context Person::hasBirthday() post: self.age=self.age@pre+1
A Person has 2 parents at max. context Person inv: self.parents->size()<=2
After somebody has a child, his/her child-set is not empty, and it is larger than before. context Person::getsChild() post: self.childs->notEmpty() and self.childs->size() > self.childs@pre->size()
Only an adult can be owner of a car. context Person inv: self.age<18 implies self.cars->isEmpty()
The first registration of a car can not be before it is built. context Auto inv: self.registration>=self.constructionYear
Every Person that has a car has at least one car which is younger than the Person. context Person inv: self.cars->notEmpty() implies self.cars->exists( c | Calendar.YEAR - c.constructionYear < self.age)
Nobody can be his/her own parent. context Person inv: self.parents->excludes(self)
There's at least one Person which owns a car. context Person inv: Person.allInstances()->exists(p | p.cars->size() > 0)


Extensions

Eclipse OCL[5] extends Standard OCL with additional operators and a type for Maps. AgileUML extends Standard OCL with Map and Function types.[6] These extensions are consistent with the map and function types present in modern programming languages such as Python and Swift.

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. 3.0 3.1 This article is based on material taken from Object+Constraint+Language at 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.
  4. Imran Sarwar Bajwa (October 2010). OCL Constraints Generation from Natural Language Specification, 2010. IEEE. doi:10.1109/EDOC.2010.33. 
  5. "Eclipse OCL™ (Object Constraint Language)". 31 January 2013. https://projects.eclipse.org/projects/modeling.mdt.ocl. 
  6. Lano, Kevin; Kolahdouz-Rahimi, Shekoufeh (2021). "Extending OCL with Map and Function Types". Fundamentals of Software Engineering. Lecture Notes in Computer Science. 12818. pp. 108–123. doi:10.1007/978-3-030-89247-0_8. ISBN 978-3-030-89246-3. https://link.springer.com/chapter/10.1007/978-3-030-89247-0_8.