Title: OCL in a small nutshell
1OCL in a small nutshell
- Jairson Vitorino, Cin UFPE
- May, 2nd 2005
2Contents
- Motivation
- What is OCL?
- Uses of OCL
- Examples
- References
3Motivation
- Are you serious about your UML models?
- (source www.empowertec.de)
4What is OCL?
- The Object Constraint Language (OCL) is a query
language that can be used to define expressions
on object oriented models (UML). - OCL enrich the models with unambiguous
information, formalizing knowledge about the
underlying business domain.
5It is a formal language, but Yes! You can
understand it and even use it!
6Uses of OCL
- Constraints are the most prominent use.
- Initialization expressions can be used to specify
an initial value for an attribute or an
association. - OCL expressions can be used to specify the
algorithm that is to be used for derived
attributes, i.e. values that are calculated from
other attributes or associations. - OCL expressions can be used to specify the
implementation of methods as long as they do not
have side effects (i.e. the method is 'read
only').
7A trivial Example
optional
You can refer to the previous state of na object
context Stackpop() Object pre notEmpty
isEmpty() false post topElementReturned
result self_at_pre.top() post topElementRemoved
top() ltgt self_at_pre.top() context Stacktop()
Object pre notEmpty isEmpty() false
context Stackpush(anObject Object) void
post pushedObjectIsOnTop top() anObject
8A more typical example
9And typical constraints...
No employee may be older than 65 years
OCL equivalent
context Company inv self.employee-gtforAll(age lt
65)
And what about this one? What does it mean?
context Company inv employee-gtexists(isUnemploye
d) false
10More examples in the PDF
11Tools
- Octopus Plug-in for Eclipse
- (syntatical checking on class diagrams, cool
editor and generates java code!)
http//www.klasse.nl/english/research/octopus-intr
o.html - OCLE
- From Romenia, syntantical checking, model
checking, comes with full UML meta-model and
well-formdness rules for diagrams consistency in
OCL! Generates java code) http//lci.cs.ubbcluj.ro
/ocle/overview.htm - OCL-AddIn for Rational Rose, similar to Octopus
but do not generate code. - http//www.empowertec.de/products/rational-rose-oc
l.htm
12Conclusions and further motivation
- UML without OCL is only useful for extreme
programming, disposable models - OCL is key for formal methods, UML models as
first-class, strategic, reusable artefacts and
(future) automated code generation
13References
- http//www.omg.org
- http//www.empowertec.de
- Presentation Object Constraint Language (OCL) by
Tevfik Bultan (www.cs.ucsb.edu/bultan/courses/272
/OCL.ppt) - Introduction to OCL, Andreas Roth
- (i12www.ira.uka.de/aroth/ lehre/keypraktWS0304/oc
lIntro.pdf)