The role of OCL in the Model Driven





























![Guards open close [ contents=capacity ] Bottle capacity : Integer contents : Integer weight Guards open close [ contents=capacity ] Bottle capacity : Integer contents : Integer weight](https://slidetodoc.com/presentation_image_h2/a483cc15a83d789e86823212965b993d/image-30.jpg)
















![UML Metamodel Rules [2] An Association. Class cannot be defined between itself and something UML Metamodel Rules [2] An Association. Class cannot be defined between itself and something](https://slidetodoc.com/presentation_image_h2/a483cc15a83d789e86823212965b993d/image-47.jpg)










- Slides: 57
The role of OCL in the Model Driven Architecture Jos Warmer Klasse Objecten J. Warmer@klasse. nl http: //www. klasse. nl
Part 1 The role of modeling in software development. Klasse Objecten
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 Klasse Objecten
MML 0: No Specification of software is kept in the heads of the developers. My software … Klasse Objecten
MML 1: Textual Specification of software is written down in one or more natural language documents. Klasse Objecten
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. Klasse Objecten
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. Klasse Objecten
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. Klasse Objecten
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 ( ). Klasse Objecten
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: ? ? ? Klasse Objecten
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 Klasse Objecten
MDA Overview Automatic transformation from platform independent model (PIM) to platform specific models (PSM). – PIM usually written in UML. – PSM can be diverse: • Java, J 2 EE, SQL, C++, . NET, COBOL, C#, CORBA, XML, etc. – Bridges between PSMs generated as well. Klasse Objecten
MDA Example Platform Independent Model PSM SQL - EJB PSM EJB - JSP PSM JSP Klasse Objecten
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. Arc. Styler, Optimal. J). Klasse Objecten
Part 2: OCL Klasse Objecten
Object Constraint Language OCL is about objects OCL is a language OCL is not just about constraints OCL is the UML expression / query language Klasse Objecten
History of OCL Syntropy influenced by Z Language for Business Modeling IBM/Objec. Time OMG submission Part of UML standard Extended and formally defined for UML 2. 0 Klasse Objecten
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 (? ) Klasse Objecten
Example Model Bottle capacity : Integer contents : Integer weight : Integer diameter : Integer neck. Diameter : Integer Crate 0. . * bottles total. Weight() : Integer 0. . 1 crate capacity : Integer max. Weight : Integer max. Diameter : Integer total. Weight() : Integer add. Bottle(b : Bottle) 0. . * crates 0. . 1 pallet bottle 0. . 1 cap 0. . 1 Cap inner. Diameter : Integer weight : Integer Pallet 0. . * / caps capacity : Integer max. Weight : Integer total. Weight() : Integer add. Crate(c : Crate) Klasse Objecten
Invariants on Classes context Crate -- the number of bottles may not exceed its capacity inv: bottles->size() <= capacity -- each bottle must fit in the crate inv: bottles->for. All(diameter < max. Diameter) -- the total weight must be less than the maximum inv: total. Weight() <= max. Weight Klasse Objecten
Invariants on Classes context Crate -- each bottle must fit in the crate inv: bottles->for. All(diameter < max. Diameter) FORALL b : Bottle FROM bottles ISTRUE b. diameter < max. Diameter Klasse Objecten
State invariants context Bottle state Closed inv: contents = capacity open Bottle capacity : Integer contents : Integer weight : Integer diameter : Integer neck. Diameter : Integer closed total. Weight() : Integer Klasse Objecten
Design by Contract Pre- and post-conditions Takes “Design by Contract” principle into “Analysis by Contract” Klasse Objecten
Preconditions on Operations context Crate: : add. Bottle( b : Bottle ) -- there must be room in the crate pre: bottles->size() < capacity -- the maximum weight for the crate may not be exceeded pre: total. Weight() + b. total. Weight() <= max. Weight -- the bottle is not in the crate pre: not bottles->includes( b ) -- ‘b’ is added to the collection of bottles post: bottles = bottles@pre->including(b) Klasse Objecten
Use Case Pre/Postcondtions A use-case can be viewed as a “system function”. Use case assumptions and results can be specified in OCL. Klasse Objecten
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 Klasse Objecten
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(winner. Mark = true)->size() <= crates->size() SIZEOF SELECT c : Cap FROM self. caps WHERE c. winner. Mark = true <= SIZEOF self. crates Klasse Objecten
Initial values and derivations -- The caps in a pallet are derived: context Pallet: : cap derive: crates. bottles. cap->as. Set() context Bottle: : contents init: 0 Klasse Objecten
Operation body The body of a query operation can be specified in OCL context Bottle: : total. Weight() : Integer body: weight + cap. weight context Crate: : total. Weight() : Integer body: weight + bottles. total. Weight()->sum() Klasse Objecten
Guards open close [ contents=capacity ] Bottle capacity : Integer contents : Integer weight : Integer diameter : Integer neck. Diameter : Integer total. Weight() : Integer closed Klasse Objecten
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. … Klasse Objecten
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 Klasse Objecten
Part 3: The MDA Framework Klasse Objecten
MDA is defined around: – Models – Model Transformations Important model types: – PIM : Platform Independent Model – PSM : Platform Specific Model Klasse Objecten
Basic MDA Framework Source Target. Code PSM Transformation Model Tool PIM Klasse Objecten
MDA Framework Source Model Transformation definition Transformation Tool Target Model Transformation tool Klasse Objecten
MDA To enable this we need – Modeling languages – Transformation definitions Klasse Objecten
MDA Framework Transformation definition Language Is written in Is used by Source Model Is written in Target Model Transformation tool Klasse Objecten
Defining Languages metamodel Is written in meta language Is defined by model Is written in Language Klasse Objecten
MDA Framework Is written in Meta language Is written in Transformation definition Language Is written in Source Model Language Is used by Is written in Target Model Transformation tool Klasse Objecten
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 Klasse Objecten
Meta language Is written in Transformation definition Language Is written in Source Model Language Is used by Transformation tool Is written in Target Model Klasse Objecten
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 Rf. P for Query/Views/Transformations Klasse Objecten
Part 3: OCL in MDA Klasse Objecten
OCL in MDA OCL is essential for MDA in three ways – More precise models – Definition of Modeling Languages – Transformation definitions Klasse Objecten
Defining Languages UML metamodel Context Class inv: attributes->is. Unique(name) Class name : Integer 1 0. . * owner attributes Attribute name : String Klasse Objecten
UML Metamodel Rules [2] An Association. Class cannot be defined between itself and something else. self. all. Connections->for. All(ar | ar. participant <> self) [1] An Interface can only contain Operations. self. all. Features->for. All(f | f. ocl. Is. Kind. Of(Operation) or f. ocl. Is. Kind. Of(Reception)) Klasse Objecten
UML Profile Rules for e. g. Java profile: context Class inv: generalizations->size() <= 1 Other profiles: – EDOC, CORBA, C++, EAI, UML-EJB, SPE, etc. Klasse Objecten
Transformation Definition Company name : Integer employees : Set(Person) name : Integer transforms to 0. . * employees Person name : String Klasse Objecten
Transformation Definitions Transformation Many. Association. To. Attribute (UML, UML) { source ae : UML: : Association. End ; target att : UML: : Attribute; source condition ae. multiplicity = Multiplicity. Kind: : many; target condition att. visibility = Visibility. Kind: : public and att. type. is. Type. Of(Set); mapping ae. name <~> att. name; ae. type <~> att. type. element. Type; } Klasse Objecten
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 Klasse Objecten
Questions Klasse Objecten
Part 4: Current Status Klasse Objecten
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 Klasse Objecten
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. Klasse Objecten
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 Klasse Objecten
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 Klasse Objecten