Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Object Constraint Language
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{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 [[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 [[Meta-Object Facility]] (MOF) [[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 == OCL is a descendant of [[Syntropy (Software)|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: # a context that defines the limited situation in which the statement is valid # a property that represents some characteristics of the context (e.g., if the context is a class, a property might be an attribute) # an operation (e.g., arithmetic, set-oriented) that manipulates or qualifies a property, and # 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.<ref name="FOLDOC" /> 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 [[Object Management Group|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 tree|(XML) tree]]s while OCL makes it possible to navigate [[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 language|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> {| class="wikitable" |+ Examples !Constraint !OCL Equivalent |- |The age of a person is not negative. |<code>'''context''' Person '''inv''': self.age >=0</code> |- |A person is younger than its parents. |<code>'''context''' Person '''inv'''<nowiki>: self.parents->forAll(p|p.age>self.age)</nowiki></code> |- |After a birthday, a person becomes one year older. |<code>'''context''' Person::hasBirthday() '''post''': self.age=self.age@pre+1</code> |- |A Person has 2 parents at max. |<code>'''context''' Person '''inv''': self.parents->size()<=2</code> |- |After somebody has a child, his/her child-set is not empty, and it is larger than before. |<code>'''context''' Person::getsChild() '''post''': self.childs->notEmpty() and self.childs->size() > self.childs@pre->size()</code> |- |Only an adult can be owner of a car. |<code>'''context''' Person '''inv''': self.age<18 '''implies''' self.cars->isEmpty()</code> |- |The first registration of a car can not be before it is built. |<code>'''context''' Auto '''inv''': self.registration>=self.constructionYear</code> |- |Every Person that has a car has at least one car which is younger than the Person. |<code>'''context''' Person '''inv''': self.cars->notEmpty() '''implies'''<nowiki> self.cars->exists( c | </nowiki>'''Calendar.YEAR''' - c.constructionYear < self.age)</code> |- |Nobody can be his/her own parent. |<code>'''context''' Person '''inv''': self.parents->excludes(self)</code> |- |There's at least one Person which owns a car. |<code style="white-space: nowrap">'''context''' Person '''inv'''<nowiki>: Person.allInstances()->exists(p | p.cars->size() > 0)</nowiki></code> |} <br /> == 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. == See also == * [[Computer model]] * [[Data mapping]] * [[Domain Specific Language]] (DSL) * [[Domain-specific modelling]] (DSM) * [[Eclipse (software)|Eclipse]] [https://web.archive.org/web/20060407092135/http://www.eclipse.org/gmt/ GMT Project] * [[Gello Expression Language]] * [[Glossary of Unified Modeling Language terms]] * [[List of UML tools]] * [[Meta-modeling]] * [[Meta-modeling technique]] * [[Meta-Object Facility]] (MOF) * [[Metadata]] * [[Model-based testing]] (MBT) * [[Model-driven architecture]] (MDA) * [[Model Driven Engineering]] (MDE) * [[Model Transformation Language]] (MTL) * [[Modeling language]] * [[Modeling perspectives]] * [[MOFM2T]] * [[Object-oriented analysis and design]] (OOAD) * [[QVT|MOF Queries/Views/Transformations]] (QVT) * [[Semantic translation]] * [[Transformation language]] (TL) * [[UML tool]] * [[Vocabulary-based transformation]] * [[XML Metadata Interchange|XMI]] * [[XML transformation language]] (XTL) == References == {{Reflist}} == External links == * [http://www.omg.org/spec/OCL/ OMG OCL specification] * [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://octopus.sourceforge.net/ Octopus: OCL Tool for Precise Uml Specifications] (OCL checker) * {{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) * [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] * [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) * [http://modeling-languages.com/ocl-tutorial/ OCL tutorial] * [https://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5630350/ NL2OCL] (OCL Tool for invariant generation from NL) {{Query languages}} {{ISO standards}} [[Category:Unified Modeling Language]] [[Category:Formal specification languages]] [[Category:ISO standards]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Foldoc
(
edit
)
Template:ISO standards
(
edit
)
Template:Query languages
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Update
(
edit
)
Template:Usurped
(
edit
)