1 Kyung Hee University Constraints Spring 2001. 2 Kyung Hee University Graphical Notations  Graphical notations are well suited for displaying structural.

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
OCL2 April A presentation of OCL 2 Object Constraint Language Christian Hein, Fraunhofer FOKUS April 2006.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Copyright © Cengage Learning. All rights reserved. CHAPTER 1 SPEAKING MATHEMATICALLY SPEAKING MATHEMATICALLY.
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Essentials of class models. 2 A very simple class model In UML, a class is shown in a class diagram as a rectangle giving its name.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 12: Constraints.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 12: Constraints.
MORE ON CLASS MODELS Lecture Outline Aggregation and composition Roles Navigability Qualified association Derived association Constraints Association.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 Class and Object Diagrams PRACTICAL OBJECT-ORIENTED DESIGN WITH.
Common Mechanisms in UML
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
Databases Illuminated Chapter 7 The Object-Oriented Model.
UML Class Diagrams: Basic Concepts. Objects –The purpose of class modeling is to describe objects. –An object is a concept, abstraction or thing that.
Object-Oriented Analysis and Design
SEG4110 – Advanced Software Engineering and Reengineering TOPIC E Object Constraint Language (OCL)
Data Modeling Using the Entity-Relationship Model
Analyzing the Requirements with Formal Specifications Vienna Development Method Specification Language (VDM-SL) Book: Formal Software Development From.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Interaction Modeling. Introduction (1) Third leg of the modeling tripod. It describes interaction within a system. The class model describes the objects.
Model-Based Specification CIS 376 Bruce R. Maxim UM-Dearborn.
111 Writing Protocols in OCL CS 4311 Jos B. Warmer and Anneke G. Kleppe, OCL: The Constraint Language of the UML, JOOP, May Jos B. Warmer and Anneke.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 9: Interaction.
© 2010 Bennett, McRobb and Farmer1 Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
WXGC6102: Object-Oriented Techniques Specifying Operations References: Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
Uml is made similar by the presence of four common mechanisms that apply consistently throughout the language. After constructing or developing the architecture.
More About Classes Ranga Rodrigo. Information hiding. Copying objects.
Unified Modeling Language © 2002 by Dietrich and Urban1 ADVANCED DATABASE CONCEPTS Unified Modeling Language Susan D. Urban and Suzanne W. Dietrich Department.
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
9-1 © Prentice Hall, 2007 Chapter 9: Analysis Classes Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey.
1 Kyung Hee University Class Diagrams Spring 2001.
Object Oriented Software Development
1 Kyung Hee University Diagram Editor : Design View Spring 2001.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
Design Model Lecture p6 T120B pavasario sem.
Home Work. Design Principles and Weak Entity Sets.
Object Oriented Analysis and Design Class and Object Diagrams.
Copyright © Cengage Learning. All rights reserved.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
1 Kyung Hee University Modeling with Objects Spring 2001.
7-1 © Prentice Hall, 2007 Topic 7: Analysis Classes Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Java-02 Basic Concepts Review concepts and examine how java handles them.
Communication Diagrams Lecture 8. Introduction  Interaction Diagrams are used to model system dynamics  How do objects change state?  How do objects.
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Kyung Hee University System Functional Model OOSD 담당조교 석사과정 이정환.
1 Kyung Hee University Interaction Diagrams Spring 2001.
UML Review: State Machines. Sept. 17, 2003Lecture 5: CS660 Fall Overview States Transitions Activities Modeling object lifeline Creating well-structured.
Jan Pettersen Nytun, UIA, page 1. Jan Pettersen Nytun, UIA, page 2 HISTORY COLLECTION TYPES AND QUERING IN OCL FORMAL LANGUAGE - STATEMENT EXAMPLES CONSTRAINTS.
Data Modeling Using the Entity- Relationship (ER) Model
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Analysis Classes Unit 5.
Visit for more Learning Resources
Used to help understand requirements more completely
Chapter 7: Entity-Relationship Model
Business Process Measures
The Object Constraint Language
Discrete Structure II: Introduction
UML Class Diagrams: Basic Concepts
Systems Analysis and Design With UML 2
The Object Constraint Language
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Object Constraint Language (OCL)
Formal Methods in Software Engineering 1
Presentation transcript:

1 Kyung Hee University Constraints Spring 2001

2 Kyung Hee University Graphical Notations  Graphical notations are well suited for displaying structural aspects of systems, but less effective for documenting the fine details of a system’s specification. One disadvantage is that graphical notation can quickly become very complex.  Graphical notations can be supplemented where necessary by textual annotations which state properties that are not implied by the diagram. Such annotations are known as constraints  A constraint is an assertion about a model element, often a class, which states properties that must be satisfied in a legal model of the system.

3 Kyung Hee University Graphical Notations (cont’d)  Constraints are written in UML in braces ‘{‘ and ‘}’ in or near the model element that they describe. UML defines standard constraints for a handful of common situations.  More general constraints can be written either in informal English, in a more formal constraints language, or even using the notation of the target programming language.  UML defines a constraint language, called the Object Constraint Language or OCL Figure 9.1 A constrained saving account

4 Kyung Hee University Standard Constraints  ‘New’ and ‘Destroyed’ are simple examples of the standard constraints defined by UML Two other commonly used standard constraints describe properties of pairs of related associations

5 Kyung Hee University Standard Constraints (cont’d)  The subset constraint The subset constraint can be applied to pairs of associations that link the same classes, and states that the set of links which are instances of one associations with a dependency arrow to which the constraint is attached In general, this constraint means that if two objects are linked by an instance of the association at the tail of the dependency arrow, they must also be linked by an instance of the association at the head of the dependency arrow

6 Kyung Hee University Standard Constraints (cont’d)  The xor constraint The xor constraint can be applied to pairs of associations that are connected at one end to the same class. It is used to specify that an instance of the shared class can not participate in both associations at the same time Figure 9.3 The xor constraint The xor constraint can be applied to pairs of associations that are connected at one end to the same class. It is used to specify that an instance of the shared class can not participate in both associations at the same time

7 Kyung Hee University Standard Constraints (cont’d) In general, this constraint means that an instance of the class that is connected to both the constraint associations can at any given time participate in a link from one of the associations or the other, but not both. Notice that this means that the multiplicity of the constrained associations must include the zero case.

8 Kyung Hee University The Object Constraint Language  The object constraint language The standard constraint are useful in particular cases, but in order to handle the arbitrary constraints that can arise on modeling a constraint specification language is required. OCL, the Object Constraint Language, is a text-based formal language which allows completely general constraints to be written for the elements appearing in UML models, particularly in class diagrams.

9 Kyung Hee University Standard Constraints (cont’d)  OCL has to provide three essential capabilities The ability to specify which model element is being constrained The ability to navigate through a model to identify other objects which may be relevant to the constraint being defined The ability to make assertions about the relationships between the context object and any objects retrieved by means of navigation expressions

10 Kyung Hee University The Context of A Constraint  Every OCL constraint has a context, which is simply the model element that is being constrained  Sometimes, the context of a constraint will be a class  If context is a class, this can be done by writing the constraint in the class symbol near the element constrained Figure 9.5 A simple constraint

11 Kyung Hee University The Context of a Constraint (cont’d)  Constraints can also be written in textual form, instead of being shown on a diagram. In this case, the context needs to be explicitly recorded  The keyword ‘self’ in the textual form of the constraint simply refers to the current context object  This notation is clearly chosen to resemble the notation used in languages such as Java and C++ for accessing features of classes SavingsAccount self.balance > 0 and self.balance <

12 Kyung Hee University Navigation Expressions  The use of constraints is not limited to stating the invariants of classes considered in isolation.  Many constraints place restriction on relationships between model elements  Informal links to gain access to other objects Navigation expressions

13 Kyung Hee University Navigation Expressions (cont’d)  A self-association on the employee class shows who in the company is managed by whom. A qualified association allows individual employees to be accessed by a unique payroll number

14 Kyung Hee University Navigation Expressions (cont’d)  The association between the person and company classes represents the relationship of a person working for the company  Following links The basic form of navigation involves following links from one object to another To show navigation, role names on the association end opposite the context object are written after the name of that object, using dot notation for attributes Department Self.staff

15 Kyung Hee University Navigation Expressions (cont’d) If an association has no role name, the name of the class at the further end of the association is used instead, with a lower-case initial letter The class name cannot be used in this way if there is any danger of ambiguity, for example if there are two associations between a pair of classes. In this case, suitable role names must be added to the associations to allow the required navigation expressions to be formed unambiguously Company Self.department

16 Kyung Hee University Navigation Expressions (cont’d)  Collections A navigation expression denotes the object that are retrieved by following the specified links from the context object Depending on the multiplicities of the associations traversed, however, the number of such objects may vary Person Self.department Person Self.manager

17 Kyung Hee University Navigation Expressions (cont’d) In general, in OCL a navigation expression that can return more that one object is said to return a collection, whereas others simply return single objects  Iterated traversal Navigation expressions are not limited to following a single association. More complicated paths through a diagram can be described by writing a sequence of role or class names, separated by dots. Company Self.department.staff

18 Kyung Hee University Navigation Expressions (cont’d)  Traversing qualified associations Qualified associations can be used in navigation just as well as ordinary ones, but they provide an additional capacity for locating individual objects. When navigating towards the qualifier, there is no difference between a qualified and an unqualified association. Person Self.employer

19 Kyung Hee University Navigation Expressions (cont’d) When navigating in the opposite direction, however, the qualifier provides a way of picking out a particular employee whose payroll number is known. This notation can be freely combined with subsequent navigation or selection of attributes. For example, the following expression returns the manager of the employee with payroll number Company Self.employee[314159] Company Self.employee[314159].manager

20 Kyung Hee University Navigation Expressions (cont’d)  Using association classes Navigate from an instance of an association class to the objects at the ends of the association, using role names or class names as normal. Grade Self.contract.employee Person Self.contract.grade

21 Kyung Hee University Objects and Collections  OCL is designed so that in many situations the distinction between individual objects and collections, or between different kinds of collections, can be ignored.  Operations on objects Apart from collections, the types available in OCL consist of basic types representing boolean values, real and integer numbers and strings, and model types corresponding to classes defined in the UML model for which constraints are being written Expression Person Self.age() Self.contract.grade.salary

22 Kyung Hee University Objects and Collections (cont’d)  Different types of collection Department staff.contract.grade representing the collection of grade objects for the employees in the department A form of collection which can contain duplicate items  bag

23 Kyung Hee University Objects and Collections (cont’d)  Operations on collections OCL defines a number of basic operations on collections of all types. One of these is an operation ‘sum’, which adds together all the elements in the collection and returns the total. Using this operation, the total salary bill for a department could be defined as shown below. Notice that the symbol ‘->’ is used in OCL indicate that a collection operation is being applied Department Staff.contract.grade.salary->sum()

24 Kyung Hee University Objects and Collections (cont’d) Another useful operation (return the value) This particular example could be handled if it was possible to form a new collection by picking out the required employees from the larger collection returned by simple navigation. OCL provides a number of operations on collections to perform such tasks.  including the declaration of a ‘local variable’ which provides a context for navigation in the boolean expression Department staff.contract.grade.asSet()->size Company employee->select(p:Person | p.contract.grade.salary > 50000)

25 Kyung Hee University Objects and Collections (cont’d) Retrieving the managers of highly paid employees Company Employee.select (contract.grade.salary > 5000).manager Department Staff -> collect (p : Person | p.age ( )) retuning the ages of all the employees in a department Company Contract.grade -> collect (salary * 1.1) -> sum ( ) using a collect expression to calculate the company’s salary

26 Kyung Hee University Objects and Collections (cont’d) Deparment Self.staff -> collect (name) Self.staff.name equivalent ways of returning the names of all the employees in a department

27 Kyung Hee University Constraint  Basic constraints standard operators : ‘=‘, ‘<>’ for equality and inequality Person Self.employer = self.department.company Company Employee -> select (age () isEmpty Employee -> select (age () size = 0 the assertion that all employees are aged 18 or over, and often be formalized by defining a collection

28 Kyung Hee University Constraint (cont’d) Department Company.employee->includesAll(staff) Person Employee.grade->includes(contract.grade) every employee’s grade is one of the set of grades linked to that employee’s company the staff of department are all employees of the company the department belongs to

29 Kyung Hee University Constraint (cont’d)  Combining constraints Constraints can be combined using the boolean operators ‘and’, ‘or’, ‘xor’,’not’. OCL differs from most programming languages in defining a boolean operator representing implication. Person self.age() > 50 implies self.contract.grade.salary > 2500

30 Kyung Hee University Constraint (cont’d)  Iterative constraints Iterative constraints resemble iterative operators such as ‘select’ in that they are defined over collections, and return a result which is determined by applying a boolean expression Rather than returning a new collection, however, they return a boolean value which depends on the results obtained for each individual element. Company self.grade->forAll (g | not g.contract->isEmpty()) Department Staff -> exists (e | e.manager -> isEmpty ())

31 Kyung Hee University Constraint (cont’d) Grade salary > Grade Grade.allInstance->forAll(g | g.salary > 20000) Grade Grade.allInstance->forAll(g : Grade | g <> self implies g.salary <> self.salary)

32 Kyung Hee University Stereotyped Constraints  Constraints are commonly used to state properties of a class and its operations that cannot be represented graphically.  Include limitations on the possible states of instances of the class, and certain aspects of the operations defined in the class.  Class invariants A class invariant is a property of a class that is intended to be true at all times for all instance of the class. Figure 9.7 class specification using constraints SavingAccount balance > 0 and balance <

33 Kyung Hee University Time events  Preconditions and postconditions Even if an invariant is defined for a class, there is no guarantee that the operations of the class will ensure that the invariant is maintained. Preconditions and postconditions are special constraints that can be written for operations. Precondition is something that must be true just before an operation is called. And usually expressed as a constraint relating the attributes of a class instance and the actual parameters of the operation being specified Postcondition is something that must be true just after operation has completed. And typically specify the effect of an operation by comparing the attributes values before and after execution of the operation SavingAccount :: withdraw (amt) Pre: amt < balance Post : balance = -

34 Kyung Hee University Constraints and Generalization  Generalization relationships do not give rise to any navigable relationships between object, and so they do not feature explicitly in constraints Figure 9.8 Polymorphic account holding

35 Kyung Hee University Constraints and Generalization Customer Account->size > 0 implies Account->select(oc1IstypedOf(currentAccount))->size 1 Individual Account-> forAll (a | a.oclType) = personalAccount)