1 / 56

OCL and Modeling

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

megan-kirk
Download Presentation

OCL and Modeling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Operations and Methods • To specoify guard • Use as a navigation language • To specify operation constrains • operation(a : Type1, b : Type2) = expression UML Semantics

  2. Flight <<invariant>> duration < 4 duration: Integer 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 : UML Semantics

  3. Flight departing Flights origin Airport departTime: Time /arrivalTime: Time duration : Interval maxNrPassengers: Integer * name: String * arriving Flights desti- nation (.) Dot Notation context Flight inv: origin <> destination inv: origin.name = ‘NRT’ context Flight inv: airline.name = ‘JAL’ UML Semantics

  4. Collection Operation in OCL • Not (.) but (->) for collection operations • collection->operation collection->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 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 • Companyself.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. Feature GeneralizableElement isRoot : Boolean isLeaf : Boolean isAbstract : Boolean visibility : {public, private, protected} Class isActive : Boolean UML Meta Model • UML Model by UML(+OCL+NL) * Abstract Syntax:  ・UML Class Diafram  ・Annotations(OCL+NL) Classifier isActive Object of Class has a control shred or not Well-formedness Rukes (OCL): Semantics :NL not self.isAbstract implies self.allOperations->forAll(op | self.allMethods->exists(m | m.specification includes (op))) Class describes Completely Object structures and behaviors・・・ 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> UML Semantics

  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 SyntaxCore:Backbone Examples of Meta-model and OCL

  26. UML Abstract SyntaxCore-Relation Examples of Meta-model and OCL

  27. UML Abstract SyntaxAssociationClassAnnotation 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 Features AssociationClass inherits features as specified in both Class and Association.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. AssociationClassWell-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. AssociationClassWell-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. AssociationClassSemantics 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 Syntax Core- Dependency Examples of Meta-model and OCL

  32. UML Abstract SyntaxCore- 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 Abstract Syntax State Machine-Main Examples of Meta-model and OCL

  43. UML Abstract Syntax 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. Specification and Implementation of Subsystem Spec Model Elements ・Use Case ・State Machine ・Spec Class Diagram ・Operation and Operation Spec Examples of Meta-model and OCL

  48. «realize» Subsystem : Operation Specification and Implementation Specification definition by Operations Implementation definition by Implementation Classes Specification Imple. Class Group operation1( ) : Type1 operation2( ) : Type2 operation3( ) : Type3 operation4( ) : Type4 operation5( ) : Type5 Examples of Meta-model and OCL

  49. Subsystem : Specification Implementation Using Use case and Collaboration Implementation Collaboration Use Case Spec Log in StockMgr Order Customer Order Check stock Examples of Meta-model and OCL

  50. UMLMeta Model:Foundation Examples of Meta-model and OCL

More Related