You are previewing Object Constraint Language, The: Getting Your Models Ready for MDA, Second Edition.
O'Reilly logo
Object Constraint Language, The: Getting Your Models Ready for MDA, Second Edition

Book Description

Praise for The Object Constraint Language, Second Edition

“MDA promises a revolution in the way we develop software. This book is essential reading for anyone intending to adopt MDA technology.”

         —Tony Clark, PhD
             King’s College, London

“Through examples, Jos and Anneke demonstrate the power and intuitiveness of OCL, and the key role that this language plays in implementing and promoting MDA. The theme, structure, contents, and, not lastly, the clarity of explanations recommend this book as the best advocate for learning, using, and promoting OCL, UML, and MDA. I am sure that this work will contribute in a significant manner to the development and widespread use of new software technologies.”

         —Dan Chiorean
             Head of the Computer Science Research Laboratory
             Babes-Bolyai University, Cluj

"In this thoroughly revised edition, Jos and Anneke offer a concise, pragmatic, and pedagogic explanation of the Object Constraint Language (OCL) and its different applications. Their discussion of OCL's potential role in Model Driven Architecture (MDA) is timely and offers great insight into the way that UML can be taken to the next level of automated software development practice. I highly recommend this book to anyone who is looking to get the most out of UML."

—Shane Sendall, PhD, Senior Researcher, Swiss Federal Institute of Technology in Lausanne

The release of Unified Modeling Language (UML) 2.0 places renewed emphasis on the Object Constraint Language (OCL). Within UML, OCL is the standard for specifying expressions that add vital information to object-oriented models and other object-modeling artifacts. Model Driven Architecture (MDA) relies on OCL to add the level of programming detail necessary to enable platform-specific models (PSM) to communicate with platform-independent models (PIM).

This book is a practical, accessible guide to OCL for software architects, designers, and developers. Much care has been taken during the redesign of OCL to ensure that the syntax remains readable and writable by the average software modeler. The Object Constraint Language, Second Edition, utilizes a case study to show how to exercise these compact but powerful expressions for maximum effect.

This newly updated edition

  • Explains why OCL is critical to MDA--and why UML alone is not enough

  • Introduces an SQL-like syntax to OCL

  • Defines the new language constructs of OCL 2.0

  • Demonstrates how OCL can be incorporated into code

  • Shares tips and tricks for applying OCL to real-world modeling challenges—showing which can be solved with UML and which require OCL

Using a combination of UML and OCL allows developers to realize the effective, consistent, and coherent models that are critical to working with MDA. The authors' pragmatic approach and illustrative use of examples will help application developers come quickly up to speed with this important object-modeling method—and will serve as a ready reference thereafter.



Table of Contents

  1. Copyright
  2. Praise for The Object Constraint Language, Second Edition
  3. The Addison-Wesley Object Technology Series
  4. The Component Software Series
  5. List of Figures
  6. List of Tables
  7. Foreword to the First Edition
  8. Foreword to the Second Edition
  9. Preface and Introduction
    1. Who Should Read This Book
    2. How This Book Should Be Used
    3. Typeface Conventions
    4. Information on Related Subjects
    5. Acknowledgments
  10. 1. User Manual
    1. 1. MDA and the Use of OCL
      1. 1.1. Introducing OCL
      2. 1.2. Model Driven Architecture
        1. 1.2.1. PIMs and PSMs
        2. 1.2.2. Automation of Transformations
        3. 1.2.3. MDA Building Blocks
          1. Models
          2. Modeling Languages
          3. Transformation Tools
          4. Transformation Definitions
        4. 1.2.4. MDA Benefits
        5. 1.2.5. The Silver Bullet?
      3. 1.3. Modeling Maturity Levels
        1. 1.3.1. Level 0: No Specification
        2. 1.3.2. Level 1: Textual
        3. 1.3.3. Level 2: Text with Diagrams
        4. 1.3.4. Level 3: Models with Text
        5. 1.3.5. Level 4: Precise Models
        6. 1.3.6. Level 5: Models Only
      4. 1.4. Building Better Models
        1. 1.4.1. Why Combine UML and OCL?
        2. 1.4.2. Value Added by OCL
      5. 1.5. Characteristics of OCL
        1. 1.5.1. Both Query and Constraint Language
        2. 1.5.2. Mathematical Foundation, But No Mathematical Symbols
        3. 1.5.3. Strongly Typed Language
        4. 1.5.4. Declarative Language
      6. 1.6. Summary
    2. 2. OCL By Example
      1. 2.1. The “Royal and Loyal” System Example
      2. 2.2. Adding Extra Information
        1. 2.2.1. Initial Values and Derivation Rules
        2. 2.2.2. Query Operations
        3. 2.2.3. Defining New Attributes and Operations
      3. 2.3. Adding Invariants
        1. 2.3.1. Invariants on Attributes
        2. 2.3.2. The Type of the Attribute Is a Class
        3. 2.3.3. Invariants on Associated Objects
        4. 2.3.4. Using Association Classes
        5. 2.3.5. Using Enumerations
      4. 2.4. Working with Collections of Objects
        1. 2.4.1. Using Collections Operations
          1. The size Operation
          2. The select Operation
          3. The forAll and isEmpty Operations
          4. The collect Operation
          5. More Collection Operations
        2. 2.4.2. Sets, Bags, OrderedSets, and Sequences
          1. Navigations Resulting in Sets and Bags
          2. Navigations Resulting in OrderedSets and Sequences
      5. 2.5. Adding Preconditions and Postconditions
        1. 2.5.1. Simple Preconditions and Postconditions
        2. 2.5.2. Previous Values in Postconditions
        3. 2.5.3. Messaging in Postconditions
      6. 2.6. Taking Inheritance into Account
      7. 2.7. Comments
      8. 2.8. Let Expressions
      9. 2.9. Summary
    3. 3. Building Models with OCL
      1. 3.1. What Is a Model?
        1. 3.1.1. Definitions
        2. 3.1.2. A Model Is a Consistent, Coherent Unit
        3. 3.1.3. The Context of an OCL Expression
      2. 3.2. Use UML Diagrams as a Base
      3. 3.3. Completing Class Diagrams
        1. 3.3.1. Derivation Rules
        2. 3.3.2. Initial Values
        3. 3.3.3. Body of Query Operations
        4. 3.3.4. Invariants
        5. 3.3.5. Preconditions and Postconditions
          1. Design by Contract
        6. 3.3.6. Messaging in Postconditions
        7. 3.3.7. Cycles in Class Models
        8. 3.3.8. Defining Derived Classes
        9. 3.3.9. Dynamic Multiplicity
        10. 3.3.10. Optional Multiplicity
        11. 3.3.11. Or Constraints
      4. 3.4. Completing Interaction Diagrams
        1. 3.4.1. Instances
        2. 3.4.2. Conditions
        3. 3.4.3. Actual Parameter Values
      5. 3.5. Completing Statecharts
        1. 3.5.1. Guards
        2. 3.5.2. Target of Actions
        3. 3.5.3. Actual Parameter Values
        4. 3.5.4. Change Events
        5. 3.5.5. Restrictions on States
      6. 3.6. Completing Activity Diagrams
      7. 3.7. Completing Component Diagrams
      8. 3.8. Completing Use Cases
        1. 3.8.1. Preconditions and Postconditions
      9. 3.9. Modeling Styles
        1. 3.9.1. Definitions of Attributes or Operations
        2. 3.9.2. The Subset Constraint
        3. 3.9.3. Adding Inheritance Versus Invariants
      10. 3.10. Tips and Hints
        1. 3.10.1. Avoid Complex Navigation Expressions
        2. 3.10.2. Choose Context Wisely
        3. 3.10.3. Avoid allInstances
        4. 3.10.4. Split and Constraints
        5. 3.10.5. Use the collect Shorthand
        6. 3.10.6. Always Name Association Ends
      11. 3.11. Summary
    4. 4. Implementing OCL
      1. 4.1. Implementation Process
      2. 4.2. Implementing UML Model Elements
      3. 4.3. Implementing the OCL Standard Library
        1. 4.3.1. OCL Basic Types
        2. 4.3.2. OCL Tuples
        3. 4.3.3. OCL Collection Types
          1. Simple collection operations
          2. Collection Iterators
      4. 4.4. Implementing OCL Expressions
        1. 4.4.1. Evaluation Order
        2. 4.4.2. No Side Effects
        3. 4.4.3. Getting Attribute and AssociationEnd Values
        4. 4.4.4. Let Expressions
        5. 4.4.5. Treating Instances as Collections
      5. 4.5. Merging Code Fragments
        1. 4.5.1. Derivation Rules
        2. 4.5.2. Invariants
        3. 4.5.3. Preconditions and Postconditions
        4. 4.5.4. Guards and Change Events in Statecharts
        5. 4.5.5. Code for Interaction Diagrams
      6. 4.6. Considerations for Constraints
        1. 4.6.1. When to Check Constraints
        2. 4.6.2. What to Do When a Constraint Fails
      7. 4.7. Summary
    5. 5. Using OCL for MDA
      1. 5.1. Relation of OCL to MDA
      2. 5.2. Metamodels
      3. 5.3. The OCL and UML Metamodels
        1. 5.3.1. The UML Metamodel
        2. 5.3.2. The OCL Metamodel
        3. 5.3.3. The Relationship Between the UML and OCL Metamodels
      4. 5.4. Using OCL to Define Languages
      5. 5.5. Using OCL to Define Transformations
        1. 5.5.1. Example Transformation Definition
      6. 5.6. Summary
  11. 2. Reference Manual
    1. 6. The Context of OCL Expressions
      1. 6.1. A Combined Model
        1. 6.1.1. The Context of an OCL Expression
        2. 6.1.2. The self Keyword
        3. 6.1.3. More Than One Expression to a Context
      2. 6.2. Classes and Other Types
        1. 6.2.1. Invariants
        2. 6.2.2. Definitions of Attributes or Operations
      3. 6.3. Attributes and Association Ends
        1. 6.3.1. Derivation Rules
        2. 6.3.2. Initial Values
      4. 6.4. Operations
        1. 6.4.1. Preconditions and Postconditions
        2. 6.4.2. Body of Query Operations
      5. 6.5. Expressions in Behavior Diagrams
        1. 6.5.1. Instances
        2. 6.5.2. Conditions
        3. 6.5.3. Guards
        4. 6.5.4. Actual Parameter Values
        5. 6.5.5. Target to Actions or Activities
        6. 6.5.6. Change Events
      6. 6.6. Use Cases
        1. 6.6.1. Preconditions and Postconditions
      7. 6.7. Constraints and Inheritance
        1. 6.7.1. Consequences for Invariants
        2. 6.7.2. Consequences for Preconditions and Postconditions
    2. 7. Basic OCL Elements
      1. 7.1. Expressions, Types, and Values
        1. 7.1.1. Value Types and Object Types
      2. 7.2. Basic Types and Operators
        1. 7.2.1. The Boolean Type
        2. 7.2.2. The Integer and Real Types
        3. 7.2.3. The String Type
      3. 7.3. Precedence Rules
      4. 7.4. Use of Infix Operators
      5. 7.5. Comments
    3. 8. User-defined Types
      1. 8.1. Features of User-Defined Types
        1. 8.1.1. Attributes and Operations
        2. 8.1.2. Class Operations and Attributes
      2. 8.2. Associations and Aggregations
        1. 8.2.1. Association Classes
        2. 8.2.2. Qualified Associations
      3. 8.3. Enumeration Types
    4. 9. Collection Types
      1. 9.1. The Collection Types
        1. 9.1.1. Collection Constants
        2. 9.1.2. Collection Type Expressions
        3. 9.1.3. Collections Operations
        4. 9.1.4. Treating Instances as Collections
        5. 9.1.5. Collections of Collections
      2. 9.2. Operations on Collection Types
        1. 9.2.1. Operations with Variant Meaning
          1. The equals and notEquals Operations
          2. The including and excluding Operations
          3. The flatten Operation
          4. The asSet, asSequence, asBag, and asOrderedSet Operations
          5. The union Operation
          6. The intersection Operation
          7. The minus Operation
          8. The symmetricDifference Operation
        2. 9.2.2. Operations on OrderedSets and Sequences Only
      3. 9.3. Loop Operations or Iterators
        1. 9.3.1. Iterator Variables
        2. 9.3.2. The isUnique Operation
        3. 9.3.3. The sortedBy Operation
        4. 9.3.4. The select Operation
        5. 9.3.5. The reject Operation
        6. 9.3.6. The any Operation
        7. 9.3.7. The forAll Operation
        8. 9.3.8. The exists Operation
        9. 9.3.9. The one Operation
        10. 9.3.10. The collect Operation
        11. 9.3.11. Shorthand Notation for collect
        12. 9.3.12. The collectNested Operation
        13. 9.3.13. The iterate Operation
    5. 10. Advanced Constructs
      1. 10.1. Constructs for Postconditions
        1. 10.1.1. The @pre Keyword
        2. 10.1.2. The result Keyword
        3. 10.1.3. The oclIsNew Operation
        4. 10.1.4. The isSent Operator
        5. 10.1.5. The message Operator
      2. 10.2. Operations of the OclMessage Type
        1. 10.2.1. The hasReturned and result Operations
        2. 10.2.2. The isSignalCall and isOperationCall operations
      3. 10.3. Packaging Expressions
      4. 10.4. Local Variables
      5. 10.5. Tuples and Tuple Types
      6. 10.6. Undefined Values, the OclVoid Type
      7. 10.7. Retyping or Casting
      8. 10.8. Type Conformance Rules
      9. 10.9. Accessing Overriden Features
      10. 10.10. The OclAny Type
        1. 10.10.1. Operations on OclAny
          1. The oclInState Operation
        2. 10.10.2. The allInstances Operation
    6. A. Glossary
      1. Glossary
    7. B. OCL Grammar Rules
      1. B.1. EBNF Rules for Context Declaration
      2. B.2. EBNF Rules for Expression
    8. C. A Business Modeling Syntax for OCL
      1. C.1. Introduction
      2. C.2. Informal Definition
        1. C.2.1. Iterators
        2. C.2.2. Collection Operations
        3. C.2.3. Other Differences
      3. C.3. Some Remarks on the Resemblance to SQL
      4. C.4. More Elaborate Examples
    9. D. Example Implementation
    10. E. Differences Between OCL Versions 1.1 and 2.0
      1. E.1. Syntax Changes
        1. E.1.1. Context Declaration
        2. E.1.2. Enumerations and Class Attributes and Operations
        3. E.1.3. Missing Rolenames and Using Association Classes
        4. E.1.4. Operations
      2. E.2. New Types
      3. E.3. Extra Predefined Operations
      4. E.4. New Options in Postconditions
      5. E.5. Other Changes
  12. Bibliography