the role of ocl in the model driven architecture jos warmer klasse objecten [email protected]
TRANSCRIPT
The role of OCL in theModel Driven Architecture
Jos Warmer
Klasse Objecten
http://www.klasse.nl
KlasseObjecten
Part 1
The role of modeling in software development.
KlasseObjecten
Modeling Maturity Levels
MML 0: No specification
MML 1: Textual Specification
MML 2: Text with Models
MML 3: Models with Text
MML 4: Precise Models
MML 5: Models only
KlasseObjecten
MML 0: No Specification
Specification of software is kept in the heads of the developers.
My software
…
KlasseObjecten
MML 1: Textual
Specification of software is written down in one or more natural language documents.
KlasseObjecten
MML 2: Text with Diagrams
Specification of software in one or more natural language documents…
… plus several high-level diagrams to explain the overall architecture.
+
KlasseObjecten
MML 3: Models with Text
Specification of software is written down in one or more models.
Additional natural language text is used to explain the background and motivation of the models.
+
KlasseObjecten
MML 4: Precise Models
Specification of software is written down in one or more models.– Natural language text is used to explain the
background and motivation of the models.
The models are precise enough to have a direct link with the actual code.
This is what the OMG calls MDA or Model Driven architecture.
KlasseObjecten
MML 5: Models Only
The models are precise and detailed enough to allow complete code-generation.
The code is invisible (as assembler is today).
Modeling language High level programming language.
This is future technology ().
KlasseObjecten
UML in the MMLs
MML 0: No use of UML
MML 1: No use of UML
MML 2: Moderate use of UML
MML 3: Extensive use of UML
MML 4: Extensive use of UML with OCL
MML 5: ???
KlasseObjecten
MDA and MML
OMG’s Model Driven Architecture is designed for MML level 4
– Ultimate goal is level 5
UML and OCL play an important role
KlasseObjecten
MDA Overview
Automatic transformation from platform independent model (PIM) to platform specific models (PSM).– PIM usually written in UML.– PSM can be diverse:
• Java, J2EE, SQL, C++, .NET, COBOL, C#, CORBA, XML, etc. etc.
– Bridges between PSMs generated as well.
KlasseObjecten
MDA Example
SQL - EJB EJB - JSP
Platform Independent Model
PSM JSPPSM SQL PSM EJB
KlasseObjecten
Experience in moving to MDA
Companies moving from MML 3 to MML 4 (MDA) realize the need for OCL and are using it.
Tools vendors developing tools for MDA realize the same and add support for OCL (e.g. ArcStyler, OptimalJ).
KlasseObjecten
Part 2: OCL
KlasseObjecten
Object Constraint Language
OCL is about objects
OCL is a language
OCL is not just about constraints
OCL is the UML
expression / query language
KlasseObjecten
History of OCL
Syntropy influenced by Z
Language for Business Modeling
IBM/ObjecTime OMG submission
Part of UML standard
Extended and formally defined for UML 2.0
KlasseObjecten
OCL Characteristics
Ease-of-use– Readable and writeable by wide audience
Pure expression language– Side-effect free
Specification language– Declarative and platform independent
Precision– Unambiguous, formal (?)
KlasseObjecten
Example Model
Bottlecapacity : Integercontents : Integerweight : Integerdiameter : IntegerneckDiameter : Integer
totalWeight() : Integer
CapinnerDiameter : Integerweight : Integer
0..1
cap
0..*
bottles
Cratecapacity : IntegermaxWeight : IntegermaxDiameter : Integer
totalWeight() : IntegeraddBottle(b : Bottle)
0..1bottle
0..1
Palletcapacity : IntegermaxWeight : Integer
totalWeight() : IntegeraddCrate(c : Crate)
0..1
crates0..*
pallet
crate
0..*
/ caps
KlasseObjecten
Invariants on Classes
context Crate
-- the number of bottles may not exceed its capacity
inv: bottles->size() <= capacity
-- each bottle must fit in the crateinv: bottles->forAll(diameter < maxDiameter)
-- the total weight must be less than the maximuminv: totalWeight() <= maxWeight
KlasseObjecten
Invariants on Classes
context Crate
-- each bottle must fit in the crateinv: bottles->forAll(diameter < maxDiameter)
FORALL b : Bottle FROM bottlesISTRUE b.diameter < maxDiameter
KlasseObjecten
State invariants
context Bottle
state Closed inv: contents = capacity
open
closed
Bottle capacity : Integer contents : Integer weight : Integer diameter : Integer neckDiameter : Integer
totalWeight() : Integer
KlasseObjecten
Design by Contract
Pre- and post-conditions
Takes “Design by Contract” principle into “Analysis by Contract”
KlasseObjecten
Preconditions on Operations
context Crate::addBottle( b : Bottle )
-- there must be room in the crate
pre: bottles->size() < capacity
-- the maximum weight for the crate may not be exceeded
pre: totalWeight() + b.totalWeight() <= maxWeight
-- the bottle is not in the crate
pre: not bottles->includes( b )
-- ‘b’ is added to the collection of bottlespost: bottles = bottles@pre->including(b)
KlasseObjecten
Use Case Pre/Postcondtions
A use-case can be viewed as a “system function”.
Use case assumptions and results can be specified in OCL.
KlasseObjecten
Components
Specified by an (or more) interface(s)– Operations with pre- and postconditions– Invariants on the objects described by the
interface• Show business rules for the component
OCL 2.0 Message clause– Specify user visible side-effects
KlasseObjecten
Business Rules
There may be at most as many caps with winner markers on a pallet as there are crates on the pallet:
context Pallet inv:caps->select(winnerMark = true)->size()
<= crates->size()
SIZEOF SELECT c : Cap FROM self.caps WHERE c.winnerMark = true<=SIZEOF self.crates
KlasseObjecten
Initial values and derivations
-- The caps in a pallet are derived:
context Pallet::cap
derive: crates.bottles.cap->asSet()
context Bottle::contents
init: 0
KlasseObjecten
Operation body
The body of a query operation can be specified in OCL
context Bottle::totalWeight() : Integer
body: weight + cap.weight
context Crate::totalWeight() : Integer
body: weight + bottles.totalWeight()->sum()
KlasseObjecten
Guards
open
closed
close [ contents=capacity ]
Bottlecapacity : Integercontents : Integerweight : Integerdiameter : IntegerneckDiameter : Integer
totalWeight() : Integer
KlasseObjecten
Expressions in a UML model
The target object in an interaction can be specified.
Object flows in activity diagrams
Parameters to messages and signals
… etc. …
KlasseObjecten
Queries
OCL is a Query Language– Expressive power >= SQL
• David Akehurst, Canterbury University
Boldsoft– Uses OCL exclusively as a query language to
specify the user interface
Queries can be defined on the model level
KlasseObjecten
Part 3: The MDA Framework
KlasseObjecten
MDA
MDA is defined around:– Models– Model Transformations
Important model types:– PIM : Platform Independent Model– PSM : Platform Specific Model
KlasseObjecten
Basic MDA Framework
SourceModel
TargetModel
TransformationTool
CodePIM PSMTransformation
ToolTransformation
Tool
KlasseObjecten
MDA Framework
SourceModel
TargetModel
Transformationtool
Transformationdefinition
TransformationTool
KlasseObjecten
MDA
To enable this we need– Modeling languages– Transformation definitions
KlasseObjecten
MDA Framework
SourceModel
TargetModel
Transformationtool
Language
Iswritten in Is used
by
Language
Iswritten in
Transformationdefinition
KlasseObjecten
Defining Languages
model
Iswritten in
metamodel
Isdefined by
Language
Iswritten in meta
language
KlasseObjecten
MDA Framework
SourceModel
TargetModel
Transformationtool
Transformationdefinition
Language Language
Iswritten in Is used
by
Iswritten in
Meta languageIs writtenin
Is writtenin
KlasseObjecten
Defining Transformations
A transformation definition maps– Element(s) from the source language
to– Element(s) from the target language
based on the respective language definitions
KlasseObjecten
SourceModel
TargetModel
Transformationtool
Transformationdefinition
Language Language
Iswritten in
Is usedby
Iswritten in
Meta language
Is writtenin
Is writtenin
Transformationdefinition language
Iswritten in
KlasseObjecten
Complete MDA Framework
Languages are defined by models– These are metamodels, e.g. UML
These models are written in a metamodeling language:– MOF is the OMGs metamodeling language
Transformation Definition Language– MOF RfP for Query/Views/Transformations
KlasseObjecten
Part 3: OCL in MDA
KlasseObjecten
OCL in MDA
OCL is essential for MDA in three ways– More precise models– Definition of Modeling Languages– Transformation definitions
KlasseObjecten
Defining Languages
UML metamodelContext Class inv:
attributes->isUnique(name)
Classname : Integer
Attributename : String
0..*
owner1
attributes
KlasseObjecten
UML Metamodel Rules
[2] An AssociationClass cannot be defined between itself and something else.self.allConnections->forAll(ar | ar.participant <> self)
[1] An Interface can only contain Operations.self.allFeatures->forAll(f | f.oclIsKindOf(Operation) or f.oclIsKindOf(Reception))
KlasseObjecten
UML Profile Rules
Rules for e.g. Java profile:
context Class inv:
generalizations->size() <= 1
Other profiles:– EDOC, CORBA, C++, EAI, UML-EJB, SPE, etc.
etc.
KlasseObjecten
Transformation Definition
Companyname : Integeremployees : Set(Person)
Personname : String
Companyname : Integer
Personname : String
0..* employees
transforms to
KlasseObjecten
Transformation Definitions
Transformation ManyAssociationToAttribute (UML, UML) {
source ae : UML::AssociationEnd ;
target att : UML::Attribute;
source condition
ae.multiplicity = MultiplicityKind::many;
target condition
att.visibility = VisibilityKind::public and att.type.isTypeOf(Set);
mapping
ae.name <~> att.name;
ae.type <~> att.type.elementType;
}
KlasseObjecten
References
MDA Explained, Practice and Promise of the Model Driven Architecture– ISBN unknown, to appear Spring 2003, Kleppe, Warmer & Bast
The Object Constraint Language, Precise Modeling with UML– ISBN 0-201-37940-6, 1999, Warmer & Kleppe
The Object Constraint Language, Getting Your Models Ready for MDA– ISBN 0-321-17936-6, to appear May 2003, Warmer & Kleppe
OCL 2.0 Submission– www.klasse.nl/ocl/subm-intro.html
KlasseObjecten
Questions
KlasseObjecten
Part 4: Current Status
KlasseObjecten
OCL 2.0 Submission
Authoring Team
Jos Warmer, Anneke Kleppe Klasse Objecten
Anders Ivner, Jonas Högström Boldsoft
Martin Gogolla, Mark Richters University of Bremen
Heinrich Hussmann,
Steffen Zschaler
Technical university of Dresden
Tony Clark Kings College, London
Simon Johnston Rational
KlasseObjecten
OCL 2.0 Submission
Submitters and supporters
Klasse Objecten IBM
Boldsoft Telelogic
University of Bremen Project Technology, Inc.
Technical university of Dresden Adaptive Ltd.
Kings College, London Compuware
Rational Software Corporation University of York
IONA University of Kent
Kabira Technologies, Inc.
KlasseObjecten
OCL 2.0 Submission Highlights
Full UML query language
Complete OCL metamodel full integration with UML metamodel
Concrete syntax strictly separated from abstract syntax allows alternative syntaxes, including visual ones
Semantics defined mathematically and in UML
KlasseObjecten
UML 2.0 Structure
Infrastructure (ad/00-08-08)
– Simple and extensible UML core
Superstructure (ad/00-08-09)
– Higher level UML structures
OCL (ad/00-08-10)
– General purpose UML expression language
Diagram interchange (ad/00-08-11)
– Exchange visual UML models between tools