Object Constraint Language (OCL)
OCL - Background <ul><li>OCL originated in IBM, then adopted by OMG  </li></ul><ul><li>OCL is a formal language </li></ul>
OCL-Features <ul><li>Pure expression language </li></ul><ul><li>No side effect </li></ul><ul><li>OCL expression simply del...
Need for OCL <ul><li>Specify unambiguous constraints </li></ul><ul><li>To avoid ambiguous Natural language tendencies </li...
OCL can be usefull in   Selected scenarios <ul><li>Specifying invariants </li></ul><ul><li>Specifying type invariants for ...
Context <ul><li>Self refers to contextual instance </li></ul><ul><li>Contextual instance Type is underlined </li></ul><ul>...
Pre- and Post-Conditions <ul><li>On Operation or Method </li></ul><ul><li>Can use self in expression </li></ul><ul><li>Pre...
OCL in Class Diagram <ul><li>Attribute constrained values specified with in “{}” </li></ul><ul><li>Specification of qualif...
OCL Basic Types & Values <ul><li>Types </li></ul><ul><li>OclType, OclAny </li></ul><ul><li>Boolean,Integer,Real,String </l...
Precedence Rules <ul><li>Dot and arrow operations </li></ul><ul><li>Unary not and unary minus </li></ul><ul><li>* and / </...
Objects and Properties <ul><li>Property is one of </li></ul><ul><ul><li>An Attribute </li></ul></ul><ul><ul><li>An Associa...
Properties ( Continued ) <ul><li>Operations </li></ul><ul><ul><li>May have parameters </li></ul></ul><ul><li>Association E...
Collections <ul><li>Many predefined operations </li></ul><ul><ul><li>Never change collections ( isQuery true ) </li></ul><...
Summary <ul><li>Class diagram not sufficient to specify constraints with precision </li></ul><ul><li>Need for unambiguous ...
Upcoming SlideShare
Loading in …5
×

Ocl

1,108 views

Published on

Object-oriented analysis and design(OOAD) UML Slides. for more slides refer www.scmGalaxy.com.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,108
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
30
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Ocl

    1. 1. Object Constraint Language (OCL)
    2. 2. OCL - Background <ul><li>OCL originated in IBM, then adopted by OMG </li></ul><ul><li>OCL is a formal language </li></ul>
    3. 3. OCL-Features <ul><li>Pure expression language </li></ul><ul><li>No side effect </li></ul><ul><li>OCL expression simply delivers a value </li></ul><ul><li>Modeling language </li></ul><ul><li>Not a programming language </li></ul><ul><li>Formal language </li></ul><ul><li>OCL specification part of UML specification </li></ul>
    4. 4. Need for OCL <ul><li>Specify unambiguous constraints </li></ul><ul><li>To avoid ambiguous Natural language tendencies </li></ul><ul><li>Designed for the average business or system modeler </li></ul><ul><li>Simple language to read and write </li></ul>
    5. 5. OCL can be usefull in Selected scenarios <ul><li>Specifying invariants </li></ul><ul><li>Specifying type invariants for stereotypes </li></ul><ul><li>Specifying Pre- & Post conditions </li></ul><ul><li>Describing guard conditions </li></ul><ul><li>As a navigation language </li></ul><ul><li>Specifying constraints on operations </li></ul>
    6. 6. Context <ul><li>Self refers to contextual instance </li></ul><ul><li>Contextual instance Type is underlined </li></ul><ul><li>Employee </li></ul><ul><li>self.Age </li></ul><ul><li>e:Employee </li></ul><ul><li>e.Age </li></ul><ul><li>Both the above expressions are identical </li></ul>
    7. 7. Pre- and Post-Conditions <ul><li>On Operation or Method </li></ul><ul><li>Can use self in expression </li></ul><ul><li>Previous values in postconditions </li></ul><ul><li>- Indicated by @pre </li></ul><ul><li>Typename::operationName( parameter1:Type1,…): ReturnType </li></ul><ul><li>pre: parameter1>… </li></ul><ul><li>Post: result = some function of self and parameter1 </li></ul><ul><li>Person::birthday() </li></ul><ul><li>post: age = [email_address] + 1 </li></ul>
    8. 8. OCL in Class Diagram <ul><li>Attribute constrained values specified with in “{}” </li></ul><ul><li>Specification of qualifiers ( primary key ) </li></ul><ul><li>Role names for associations </li></ul>
    9. 9. OCL Basic Types & Values <ul><li>Types </li></ul><ul><li>OclType, OclAny </li></ul><ul><li>Boolean,Integer,Real,String </li></ul><ul><li>Collections ( Set, Bag, Sequence) </li></ul><ul><li>Enumeration </li></ul><ul><li>Operation </li></ul><ul><li>Type conformance </li></ul><ul><li>Casting </li></ul>
    10. 10. Precedence Rules <ul><li>Dot and arrow operations </li></ul><ul><li>Unary not and unary minus </li></ul><ul><li>* and / </li></ul><ul><li>+ and binary – </li></ul><ul><li>And , or, xor </li></ul><ul><li>Implies </li></ul><ul><li>If-then-else-endif </li></ul><ul><li><, >, <=, >=, = </li></ul>
    11. 11. Objects and Properties <ul><li>Property is one of </li></ul><ul><ul><li>An Attribute </li></ul></ul><ul><ul><li>An AssociationEnd </li></ul></ul><ul><ul><li>An Method with isQuery being true </li></ul></ul><ul><ul><li>An Operation with isQuery being true </li></ul></ul><ul><li>Value of property specified by </li></ul><ul><li>- Dot followed by name of property </li></ul>
    12. 12. Properties ( Continued ) <ul><li>Operations </li></ul><ul><ul><li>May have parameters </li></ul></ul><ul><li>Association Ends </li></ul><ul><li>- Using rolenames </li></ul><ul><li>- Multiplicity considerations </li></ul><ul><li>Navigation </li></ul><ul><li>Pathnames for packages ( :: ) </li></ul><ul><li>- Packagename1::Packagename2::Typename </li></ul>
    13. 13. Collections <ul><li>Many predefined operations </li></ul><ul><ul><li>Never change collections ( isQuery true ) </li></ul></ul><ul><li>Concrete Types </li></ul><ul><li>- Set Set{2,4,6} </li></ul><ul><li>- Sequence Sequence{‘apple’,’orange’} </li></ul><ul><li>- Bag Bag { 1, 5, 1, 3 } </li></ul><ul><li>Collections operations </li></ul><ul><li>- select, reject, collect, forAll, exists, iterate </li></ul>
    14. 14. Summary <ul><li>Class diagram not sufficient to specify constraints with precision </li></ul><ul><li>Need for unambiguous language to specify constraints </li></ul><ul><li>Object Constraint Language is a formal language for this purpose </li></ul><ul><li>OCL is a part of ULM </li></ul>

    ×