+ All Categories
Home > Documents > 1 OCL The Role of OCL in UML. 2 רשימת הנושאים מבוא מרכיבי השפה ...

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

Date post: 17-Jan-2016
Category:
Upload: carmel-baker
View: 222 times
Download: 0 times
Share this document with a friend
35
1 OCL The Role of OCL in UML
Transcript
Page 1: 1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.

1

OCL

The Role of OCL in UML

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

2

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

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

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

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

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

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

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

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

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

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

7

OCL Constraint and EA An OCL constraint is an OCL Boolean expression

that evaluates to true or false

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

8

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

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

9

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

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

10

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

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

11

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

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

12

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

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

13

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

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

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

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

15

Operations on Real and Integer Types

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

16

Operations on String Types

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

17

Operations on Boolean Types

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

18

The OCL Collection Hierarchy

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

19

Operations on all Collections

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

20

Operations on all Collections

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

21

Specialized Collection Operations

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

22

Types of OCL expressions

Expression Type

Syntax Applies to Semantics

invariant Inv: Classifier The invariant must be true for all instances of the classifier

precondition Pre: Operation

Behavioral feature

The precondition must be true before the operation executes

postcondition Post: Operation

Behavioral feature

The precondition must be true after the operation executes

The keyword result refers to the result of the operation

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

23

Types of OCL expressionsExpression Type

Syntax Applies to Semantics

Query operation body

Body: Query operation

Defines the body of a query operation

Initial value Init: Attribute

Association

end

Defines the initial value of the attribute or the association end

define Def: Classifier Adds variables or helper operations to a context classifier

let let: OCL

expression

Adds local variables to OCL expressions

Derived value Derive: Attribute

Association

end

Defines the derivation rule for the derived attribute or association end

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

24

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

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

25

דוגמא

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

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

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

27

inv:

1. No account shall be overdrawn by more than 1000$

Context BankAccount

inv balanceValue:

self.balance>-1000

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

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

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

29

inv:

3. DepositAccounts shall never be overdrawn

Context DepositAccount

inv balanceValue:

self.balance>=0.0

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

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

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

31

OCL Example: Companies and Employees

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

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.

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

33

OCL Example

"If a person is employed at a company, it is not unemployed."

context Company

inv: employee->exists(isUnemployed) = false

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

34

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

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

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://www.omg.org/cgi-bin/doc?formal/06-05-01.pdf>. http://en.wikipedia.org/wiki/Object_Constraint_Language


Recommended