Object Constraint Language
This article needs to be updated.(April 2018) |
The Object Constraint Language (OCL) is a
Description
OCL is a descendant of
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. 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
Alternatives
Being a rule-based validation language,
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 [4] extends Standard OCL with additional operators and a type for Maps. AgileUML extends Standard OCL with Map and Function types.[5] 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 GMT Project
- Gello Expression Language
- Glossary of Unified Modeling Language terms
- Intentional Programming(IP)
- 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)
- MOF Queries/Views/Transformations (QVT)
- Semantic translation
- Transformation language (TL)
- UML tool
- Vocabulary-based transformation
- XMI
- XML transformation language (XTL)
References
- ^ Object Management Group (OMG); Object Constraint Language Specification, Chapter 7 of OMG Unified Modeling Language Specification, Version 1.3, March 2000 (first edition)
- ^ Object Management Group (OMG); Object Constraint Language OMG Available Specification Version 2.0, May 2006
- )
- ^ "Eclipse OCL™ (Object Constraint Language)". 31 January 2013.
- S2CID 239029860.
External links
- OMG OCL specification
- OCL Portal - The center for OCL related information
- OCL page of Computer Science Dept. of CSUSB (brief OCL 2.0 syntax)
- Octopus: OCL Tool for Precise Uml Specifications (OCL checker)
- Dresden OCL Toolkit (OCL Toolkit, various OCL related publications)
- HOL-OCL (An interactive theorem proof environment for OCL, various OCL related publications)
- OCL for Java tutorial on ParlezUML
- Article on using EMF's OCL in Java code
- UML link page on cetus-links.org
- USE (UML-based Specification Environment) (OCL Tool for model validation, various OCL related publications)
- OCL tutorial
- NL2OCL (OCL Tool for invariant generation from NL)