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
(section)
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!
== 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 />
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)