Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.

Similar presentations


Presentation on theme: "1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות."— Presentation transcript:

1 1 OCL The Role of OCL in UML

2 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות

3 3 Introduction  OCL notation allows Unified Modeling Language (UML) users more specification precision  Based on logic and discrete mathematics  It is a formal method…much more formal than other software engineering methods  The OCL language is used to express constraints  Constraints specify constant conditions for system being modeled  Evaluated OCL expressions can not have side effects  OCL is a pure declarative language  OCL is a typed language  OCL is UML’s formal constraint language

4 4 Why OCL?  UML diagram e.g. class, state, or activity not granular enough to provide all relevant aspects of a specification  Need to provide additional constraints about the objects in the model  Such constraints typically described with natural language which can result in uncertainty  Unambiguous constraints need formal languages but they’re often hard to understand by nonmathematical persons  OCL is a formal language for everyone

5 5 Where to use OCL  To specify invariants on classes and types in the class model  To describe pre- and post conditions on Operations and Methods  To describe Guards  To specify constraints on operations

6 6 Using OCL  Choose one or more UML diagrams---class, state, or activity  Add OCL expressions stating facts about elements of the diagrams  The expressions are called constraints  Any implementation derived from the model must remain true  Like OOP, OCL expressions operate on objects  However, the result of a complete expression must always be Boolean i.e. true or false

7 7 OCL Constraint and EA  An OCL constraint is an OCL Boolean expression that evaluates to true or false

8 8 דוגמא:אילוצים על נישואים

9 9 נישואים אילוץ 1: EA

10 10 נישואים אילוץ 2: EA

11 11 נישואים אילוץ 3: EA

12 12 נישואים אילוץ 4: EA

13 13 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות

14 14 Referring to UML Model Info  Many properties expressed in UML models can be referred to from OCL:  attributes  operations  navigation are derived from associations  class attributes and operations  states

15 15 Operations on Real and Integer Types

16 16 Operations on String Types

17 17 Operations on Boolean Types

18 18 The OCL Collection Hierarchy

19 19 Operations on all Collections

20 20 Operations on all Collections

21 21 Specialized Collection Operations

22 22 Types of OCL expressions Expression TypeSyntaxApplies toSemantics invariantInv:ClassifierThe invariant must be true for all instances of the classifier preconditionPre:Operation Behavioral feature The precondition must be true before the operation executes postconditionPost:Operation Behavioral feature The precondition must be true after the operation executes The keyword result refers to the result of the operation

23 23 Types of OCL expressions Expression TypeSyntaxApplies toSemantics Query operation body Body:Query operation Defines the body of a query operation Initial valueInit:Attribute Association end Defines the initial value of the attribute or the association end defineDef:ClassifierAdds variables or helper operations to a context classifier letlet:OCL expression Adds local variables to OCL expressions Derived valueDerive:Attribute Association end Defines the derivation rule for the derived attribute or association end

24 24 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות

25 25 דוגמא

26 26 inv: 1.No account shall be overdrawn by more than 1000$ 2.CeckingAccounts have an overdraft facility. The account shall not be overdrawn to an amount greater than its overdraft limit 3.DepositAccounts shall never be overdrawn 4.The owner must also be an operator

27 27 inv: 1.No account shall be overdrawn by more than 1000$ Context BankAccount inv balanceValue: self.balance>-1000

28 28 inv: 1.No account shall be overdrawn by more than 1000$ 2.CeckingAccounts have an overdraft facility. The account shall not be overdrawn to an amount greater than its overdraft limit Context CheckingAccount inv balanceValue: self.balance>=(-overdraftLimit) inv maximumOverdraftLimit: self.overdraftLimit<=1000

29 29 inv: 3.DepositAccounts shall never be overdrawn Context DepositAccount inv balanceValue: self.balance>=0.0

30 30 pre: post and @pre 1.The amount to be deposited shall be greater than zero 2.After the operation executes, the amount shall have been added to the balance Context BankAccount::deposit(amount:Real) Real pre : amount>0 post: self.balance=self.balance@pre + amount

31 31 OCL Example: Companies and Employees

32 32 OCL Example  "No employee may be older than 65 years." context Company inv: self.employee->forAll(age <= 65) Each OCL expression is written in the context of an instance of specific type. In an OCL expression, the reserved word self is used to refer to the contextual instance. For example, if the context is Company, the self refers to an instance of Company.

33 33 OCL Example  "If a person is employed at a company, it is not unemployed." context Company inv: employee->exists(isUnemployed) = false

34 34 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות

35 35 References  Pressman, Roger S. Software Engineering: A Practitioner’s Approach, 6/e. New York: McGraw-Hill, 2005.  Object Constraint Language Specification OMG Available Specification v2.0 May 2006.  http://en.wikipedia.org/wiki/Object_Constraint_Language


Download ppt "1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות."

Similar presentations


Ads by Google