OCL and Modeling
-
Upload
megan-kirk -
Category
Documents
-
view
64 -
download
0
description
Transcript of 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
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
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
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
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 }
UML Semantics 6
Basic types and Operations
Type OperationInteger *, +, -, /, absReal *, +, -, /, floorBoolea and, or, xor, not, implies,
if-then-elseString ToUpper, concat
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()
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?
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
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()
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 )
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 }
UML Semantics 13
Type Conformance Rules
– Set(Bicycle) ==> Set(Transport)– Set(Bicycle) ==> Collection(Bicycle)– Set(Bicycle) ==> Collection(Transport)
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)
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’ )
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) )
UML Semantics 17
Predefined OCL Types
• OclType
• OclAny
• OclExpression
• Real, Integer, String, Boolean
• Enumeration
• Collection
• Set, Bag, Sequence
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
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
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>
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
Examples of Meta-model and OCL 22
UML Meta-Model
Strucrure
Examples of Meta-model and OCL 23
Behavior Elements
Model Management
Foundation
The top structure of UML Meta Model
Examples of Meta-model and OCL 24
UML Meta Model :
Behavior Elements
Examples of Meta-model and OCL 25
UML Abstract Syntax Core:Backbone
Examples of Meta-model and OCL 26
UML Abstract Syntax Core-Relation
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.
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)
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
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.
Examples of Meta-model and OCL 31
UML Abstract SyntaxCore- Dependency
Examples of Meta-model and OCL 32
UML Abstract Syntax Core- Classifier
Examples of Meta-model and OCL 33
UML Abstract Syntax Extension Mechanism
Examples of Meta-model and OCL 34
UML Abstract Syntax Data Type - Main
Examples of Meta-model and OCL 35
UML Abstract Syntax Data Type - Expression
Examples of Meta-model and OCL 36
UML Abstract Syntax Common Behavior - Interface
Examples of Meta-model and OCL 37
UML Abstract Syntax Common Behavior - Link
Examples of Meta-model and OCL 38
UML Abstract Syntax Collaboration - Roll
Examples of Meta-model and OCL 39
UML Abstract Syntax Collaboration-Interaction
Examples of Meta-model and OCL 40
UML Abstract Syntax Collaboration-Interface
Examples of Meta-model and OCL 41
UML Abstract Syntax Use Case
Examples of Meta-model and OCL 42
UML AbstractSyntax State
Machine-Main
Examples of Meta-model and OCL 43
UML AbstractSyntax Activity
Graph
Examples of Meta-model and OCL 44
UML Abstract Syntax Model Management
Examples of Meta-model and OCL 45
Package 、 Subsystem 、 model
Examples of Meta-model and OCL 46
What’s Subsystem ?
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
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
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
Examples of Meta-model and OCL 50
UMLMeta Model : Foundation
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
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...
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
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
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
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