ocl and modeling

56
UML Semantics 1 OCL and Modeling To define Invariant Constrains of Class and Type in the Class Models To define Type Invariant of Stereotype To specify Pre and Post conditions of Opera tions and Methods To specoify guard Use as a navigation language To specify operation constrains operation(a : Type1, b : Type2) = expression

Upload: megan-kirk

Post on 02-Jan-2016

64 views

Category:

Documents


0 download

DESCRIPTION

OCL and Modeling. To define Invariant Constrains of Class and Type in the Class Models To define Type Invariant of Stereotype To specify Pre and Post conditions of Operations and Methods To specoify guard Use as a navigation language To specify operation constrains - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: OCL and Modeling

UML Semantics 1

OCL and Modeling To define Invariant Constrains of Class and Ty

pe in the Class Models To define Type Invariant of Stereotype To specify Pre and Post conditions of Operatio

ns and Methods To specoify guard Use as a navigation language To specify operation constrains

operation(a : Type1, b : Type2) = expression

Page 2: OCL and Modeling

UML Semantics 2

OCL Expression and context, inv:, self

– OCL expression1 ( self ) :context Flight inv: self.duration < 4

– OCL expression2 ( no self ) :context Flight inv: duration < 4

– Class Diagram :

Flight

duration: Integer<<invariant>>duration < 4

Page 3: OCL and Modeling

UML Semantics 3

(.) Dot Notation

context Flight

inv: origin <> destination

inv: origin.name = ‘NRT’

context Flight

inv: airline.name = ‘JAL’

Airport

Flight

*

*

departTime: Time/arrivalTime: Timeduration : IntervalmaxNrPassengers: Integer

origin

desti-nation

name: String

arrivingFlights

departingFlights

Page 4: OCL and Modeling

UML Semantics 4

Collection Operation in OCL• Not (.) but (->) for collection operations

– collection->->operationcollection->collect (e : T | expr )

collection->collect (e | expr )

collection->collect ( expr )

• (.) available in default notation:collection.expr

• example :

context Airport inv:self.arrivingFlights -> collect(airLine) ->notEmpty

Page 5: OCL and Modeling

UML Semantics 5

Basic types and Values

• Basic Types and Values– Boolean, Integer, Real, String– true, false, 1,2, 1.5, 3.14, ‘To be’

• enum Type– enum{ val1, val2, val3 }

Page 6: OCL and Modeling

UML Semantics 6

Basic types and Operations

Type OperationInteger *, +, -, /, absReal *, +, -, /, floorBoolea and, or, xor, not, implies,

if-then-elseString ToUpper, concat

Page 7: OCL and Modeling

UML Semantics 7

Object and Property• Property

– Attribute 、 Roll 、 Inquiry operation/Methods

• Attribute– Person self.age

– Person self.age >= 0

• Operation aPerson:Person, aDate:Date– aPerson.income(aDate)

– Person::income(d:Date):Integer

– Company self.stockPrice()

Page 8: OCL and Modeling

UML Semantics 8

Association and Multiplicity

• Company self.manager -- Person self.employee -- Set(Person)

• Person self.employer->size -- # of companies he works for

• Person self.employer->isEmpty -- no job now?

Page 9: OCL and Modeling

UML Semantics 9

Association and Navigation

• Navigation on Multiplicity 0..1– Company

self.manager->size -- aSet.size=1 -- to use -> to check exist or not

• Navigation to associated Class– Person self.job

• Navigation from associated Class– Job -- Associated Class

self.employer self.employee

Page 10: OCL and Modeling

UML Semantics 10

Association and Navigation

• Through Qualified Associations– Bank

self.customer -- Set(Person) self.customer[17463] -- aPerson

• Using Pathnames for Packages– Packagename::Typename

• Accessing Overridden properties of Superclass– SubClassB

self.SuperClassA::op1() self.op1()

Page 11: OCL and Modeling

UML Semantics 11

Predefined Properties on All Objects

• Operations to all objects– oclType: OclType– oclIsTypeOf(t : OclType): boolean– oclIsKindOf(t : OclTYpe): boolean

• Operations to type of self : allInstances– Person.allInstances : Set(Person)– Person.allInstances->forAll( p1, p2 |

p1 <> p2 implies p1.name <> p2.name )

Page 12: OCL and Modeling

UML Semantics 12

Collections• Collection: Set,Sequence,Bag

– Set{ 1, 2, 4, 8 }– Set{ ‘apple’, ‘orage’, ‘lemon’ }– Sequence{ 1, 2, 4, 8, 4, 2, 1 }– Sequence{ 1..10 }– Bag{ 1, 1, 2, 3, 3, 3, 1 }

• Collections of Collections are flattened !– Set{ Set{1, 2}, Set{3, 4}, Set{5,6} }– Set{ 1, 2, 3, 4, 5, 6 }

Page 13: OCL and Modeling

UML Semantics 13

Type Conformance Rules

– Set(Bicycle) ==> Set(Transport)– Set(Bicycle) ==> Collection(Bicycle)– Set(Bicycle) ==> Collection(Transport)

Page 14: OCL and Modeling

UML Semantics 14

Collection Operations• Select, Reject, Collect

– Company self.employee->select(age > 50) self.employee->select(p | p.age > 50 ) self.employee->reject( isMarried ) self.employee->collect( birthDate ) self.employee->collect(p | p.birthDate )

• Shorthand for Collect– self.employee.birthDate --Bag(Date)– self.employee.birthDate->asSet --Set(Date)

Page 15: OCL and Modeling

UML Semantics 15

For All and Exists Operation

• ForAll Operation– Company

self.employee->forAll( forname = ‘Jack’ ) self.employee->forAll( e1, e2 | e1<>e2 impliese1.forename<>e2.forename )

• exists Operations– Company

self.employee->exists( forname = ‘Jack’ )

Page 16: OCL and Modeling

UML Semantics 16

Iterative Operation

• Iterate Operation– collection->iterate( elem:Type;acc:Type=<exp

>| <exp-with-elem-and-acc> )

• reject, select, forAll. Exists, collect, elect– collection->collect( x:T | x.property )– collection=>iterate( x:T; acc:T2 = Bag{} |

acc->including(x.property) )

Page 17: OCL and Modeling

UML Semantics 17

Predefined OCL Types

• OclType

• OclAny

• OclExpression

• Real, Integer, String, Boolean

• Enumeration

• Collection

• Set, Bag, Sequence

Page 18: OCL and Modeling

UML Semantics 18

Operation Specification and OCL

• Invariant Constrain– Person self.age > 0

• Pre- and Post-condition definitions– Person::birthdayHappens()

post: age = age@pre + 1– Company::hireEmployee(p: Person)

pre: not employee->includes(p) post: employees->includes(p) and stockprice() = stockprice@pre + 10

Page 19: OCL and Modeling

UML Semantics 19

UML Meta Model

• UML Model by UML( + OCL + NL)

GeneralizableElementGeneralizableElementGeneralizableElementGeneralizableElement

isRoot : BooleanisRoot : BooleanisLeaf : BooleanisLeaf : BooleanisAbstract : BooleanisAbstract : Boolean

isRoot : BooleanisRoot : BooleanisLeaf : BooleanisLeaf : BooleanisAbstract : BooleanisAbstract : Boolean

ClassClassClassClass

isActive : BooleanisActive : BooleanisActive : BooleanisActive : Boolean

ClassifierClassifierClassifierClassifier

FeatureFeatureFeatureFeature

visibility : {public, private,visibility : {public, private,protected}protected}visibility : {public, private,visibility : {public, private,protected}protected}

**

Well-formedness Rukes (OCL) :

not self.isAbstract implies self.allOperations->forAll(op | self.allMethods->exists(m | m.specification includes (op)))

Semantics : NL

Class describes Completely Object structures and behaviors ・・・

Abstract Syntax : ・ UML Class Diafram

 ・ Annotations   (OCL + NL)

isActive Object of Class has a control shred or not

Page 20: OCL and Modeling

UML Semantics 20

4 Layers Meta-model• Meta Meta Model Layer

– Language for Meta model description : MOF– e.g. : MetaClass, MetaAttribute, MetaOperation

• Meta Model Layer– Language for Model description– e.g. : Class, Attribute, Operation, Component

• Model Layer– Language for specific domain description– e.g. : StockShare, askPrice, sellLimitOrder, StockQuoteServer

• User Object Layer– e.g. : <Acme_Software_Share_98789>, 654.56, sell_limit_order,

<Stock_Quote_Svr_32123>

Page 21: OCL and Modeling

Examples of Meta-model and OCL 21

Example of Meta-Model

• 《 metaclass 》 MOF MetaMetamodel::Class

• 《 metaclass 》 UML Metamodel::Class

• PassengerTicket

• 45723990550: PassengerTicket

• reference : UML2001:Standardization Odyssey, by Cris Kobryn

Page 22: OCL and Modeling

Examples of Meta-model and OCL 22

UML Meta-Model

Strucrure

Page 23: OCL and Modeling

Examples of Meta-model and OCL 23

Behavior Elements

Model Management

Foundation

The top structure of UML Meta Model

Page 24: OCL and Modeling

Examples of Meta-model and OCL 24

UML Meta Model :

Behavior Elements

Page 25: OCL and Modeling

Examples of Meta-model and OCL 25

UML Abstract Syntax   Core:Backbone

Page 26: OCL and Modeling

Examples of Meta-model and OCL 26

UML Abstract Syntax   Core-Relation

Page 27: OCL and Modeling

Examples of Meta-model and OCL 27

UML Abstract Syntax  

AssociationClass   Annotation

An association class is an association that is also a class. It not only connects a set of classifiers but also defines a set of features that belong to the relationship itself and not any of the classifiers.

Inherited FeaturesAssociationClass inherits features as specified in both Class and Asso

ciation.In the metamodel, an AssociationClass is a declaration of a semantic relationship between Classifiers, which has a set of features of its own. AssociationClass is a subclass of both Association and Class (i.e., each AssociationClass is both an Association and a Class); therefore, an AssociationClass has both AssociationEnds and Features.

Page 28: OCL and Modeling

Examples of Meta-model and OCL 28

AssociationClass  Well-Formedness Rules(1)

• [1] The names of the AssociationEnds and the StructuralFeatures do not overlap.– self.allConnections->forAll( ar |– self.allFeatures->forAll( f | f.oclIsKindOf(StructuralFeature) implies ar.name <> f.name ))

• [2] An AssociationClass cannot be defined between itself and something else.

• self.allConnections->forAll(ar | ar.participant <> self)

Page 29: OCL and Modeling

Examples of Meta-model and OCL 29

AssociationClass  Well-Formedness Rules(2)

• Additional operations

[1] The operation allConnections results in the set of all AssociationEnds of the AssociationClass, including all connections defined by its parent (transitive closure).

allConnections : Set(AssociationEnd);allConnections = self.connection->union(

self.parent-> select (s | s.oclIsKindOf(Association))->collect

(a : Association | a.allConnections))->asSet

Page 30: OCL and Modeling

Examples of Meta-model and OCL 30

AssociationClass   Semantics Description

• An association may be refined to have its own set of features (i.e., features that do not belong to any of the connected classifiers) but rather to the association itself. Such an association is called an association class. It will be both an association, connecting a set of classifiers, and a class, and as such have features and be included in other associations. The semantics of such an association is a combination of the semantics of an ordinary association and of a class.

• The AssociationClass construct can be expressed in a few different ways in the metamodel (e.g., as a subclass of Class, as a subclass of Association, or as a subclass of Classifier). Since an AssociationClass is a construct being both an association (having a set of association-ends) and a class (declaring a set of features), the most accurate way of expressing it is as a subclass of both Association and Class. In this way, AssociationClass will have all the properties of the other two constructs. Moreover, if new kinds of associations containing features (e.g., AssociationDataType) are to be included in UML, these are easily added as subclasses of Association and the other Classifier.

• The terms child, subtype, and subclass are synonyms and mean that an instance of a classifier being a subtype of another classifier can always be used where an instance of the latter classifier is expected. The neutral terms parent and child, with the transitive closures ancestor and descendant, are the preferred terms in this document.

Page 31: OCL and Modeling

Examples of Meta-model and OCL 31

UML Abstract SyntaxCore- Dependency

Page 32: OCL and Modeling

Examples of Meta-model and OCL 32

UML Abstract Syntax   Core- Classifier

Page 33: OCL and Modeling

Examples of Meta-model and OCL 33

UML Abstract Syntax Extension Mechanism

Page 34: OCL and Modeling

Examples of Meta-model and OCL 34

UML Abstract Syntax Data Type - Main

Page 35: OCL and Modeling

Examples of Meta-model and OCL 35

UML Abstract Syntax Data Type - Expression

Page 36: OCL and Modeling

Examples of Meta-model and OCL 36

UML Abstract Syntax Common Behavior - Interface

Page 37: OCL and Modeling

Examples of Meta-model and OCL 37

UML Abstract Syntax Common Behavior - Link

Page 38: OCL and Modeling

Examples of Meta-model and OCL 38

UML Abstract Syntax Collaboration - Roll

Page 39: OCL and Modeling

Examples of Meta-model and OCL 39

UML Abstract Syntax Collaboration-Interaction

Page 40: OCL and Modeling

Examples of Meta-model and OCL 40

UML Abstract Syntax Collaboration-Interface

Page 41: OCL and Modeling

Examples of Meta-model and OCL 41

UML Abstract Syntax Use Case

Page 42: OCL and Modeling

Examples of Meta-model and OCL 42

UML AbstractSyntax State

Machine-Main

Page 43: OCL and Modeling

Examples of Meta-model and OCL 43

UML AbstractSyntax Activity

Graph

Page 44: OCL and Modeling

Examples of Meta-model and OCL 44

UML Abstract Syntax Model Management

Page 45: OCL and Modeling

Examples of Meta-model and OCL 45

Package 、 Subsystem 、 model

Page 46: OCL and Modeling

Examples of Meta-model and OCL 46

What’s Subsystem ?

Page 47: OCL and Modeling

Examples of Meta-model and OCL 47

Spec Model Elements

・ Use Case・ State Machine・ Spec Class Diagram・ Operation and Operation Spec

Specification and Implementation of Subsystem

Page 48: OCL and Modeling

Examples of Meta-model and OCL 48

«realize»operation1( ) : Type1

operation2( ) : Type2

operation3( ) : Type3

operation4( ) : Type4

operation5( ) : Type5

Specification Imple. Class Group

Subsystem : Operation Specification and Implementation

Specification definition by Operations

Implementation definition by Implementation Classes

Page 49: OCL and Modeling

Examples of Meta-model and OCL 49

StockMgr

OrderCustomer

Log in

Order

Check stock

Use Case Spec ImplementationCollaboration

Subsystem : Specification ImplementationUsing Use case and Collaboration

Page 50: OCL and Modeling

Examples of Meta-model and OCL 50

UMLMeta Model : Foundation

Page 51: OCL and Modeling

UML in the future 51

Recent UML Versions• UML1.1 : First OMG Standard 1997.11

• UML1.3 : Technical Improvement 1999.8– Notation and Meta-Model

– Model Exchange Format definition(XML)

• UML1.4 : minor upgrade 2001.9• UML2.0 : major upgrade 2002?

– Action Semantics

– Flexible and strong Language Extension Mechanism

– Version and CFM Mechanism

– Formal Specification for UML Semantics

Page 52: OCL and Modeling

UML in the future 52

UML 2.0 (1)• Improvement of Extension

– Radical changes based on 4 Layers Meta-Model– Profile Specification for language customization

• Architecture– Physical Meta-Model definition– Reconstruct Kernel Language 、 UML Profile 、 Stand

ard Model Library and make a guide line

• Component– Support the Component based Development like EJB a

nd DCOM etc...

Page 53: OCL and Modeling

UML in the future 53

UML 2.0 (2)• Relation

– add semantics regarding Sophistication and Trasabikity– semantics among multiple Abstract levels

• State Chart Diagram and Activity Diagram– each semantics definition– introduce parallel descriptions

• Model Management– Detail definitions of Model and Subsystems for realizat

ion of the Multi-views

• General Mechanism– Version Control of Diagrams, Exchange Diagrams

Page 54: OCL and Modeling

Summary 54

Summary• How to Read UML Specifications

– Not only to guide UML notations– But also introduce to read UML Semantics

• UML is not matured as Languages– From UML1.4 to UML2.0

• Use UML according to the goals– Use the necessary parts in the SW Development– Convenient to use all over the world– Use OCL in the detail and precise spesifications

Page 55: OCL and Modeling

Summary 55

UML Resources

• UMG– /http://www.omg.org/uml/– /http://www.dstc.edu/au/mof

• UML 2.0– http://www.celigent.com/omg/adptf/wgs/uml2

wg.htm

Page 56: OCL and Modeling

Summary 56

UML Standard Books (UML 1.3)• Unified Modeling Language User Guide1999, Addison-Wesley Grady Booch, and Ivar Jacobson, Jam

es Rumbaugh• Unified Modeling Language Reference Manua1999, Addison-Wesley James Rumbaugh and Grady Booch, I

var Jacobson• The Unified Software Development Process1999, Ivar Jacobson, and Grady Booch, James Rumbaugh• The Object Constraint Language, Precise modeling with

UML2000, Addison-Wesley , Jos Warmer, Anneke Kleppe, ISBN

0-201-37940-6