Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Few comments about midterm I graded very lightly.

Slides:



Advertisements
Similar presentations
1 The Object Constraint Language: Expressing Constraints in the UML (Most slides created by Robert B. France, Professor Department of Computer Science,
Advertisements

OCL2 April A presentation of OCL 2 Object Constraint Language Christian Hein, Fraunhofer FOKUS April 2006.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Example of a Problem Statement: Introduction into.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Art for Chapter 7, Object Design.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Object Constraint Language.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Object Constraint Language.
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 9, Specifying Interfaces.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Object Design: Specifying Interfaces Chapter 9. 2 Object Design  Object design is the process of adding details to the requirements analysis and making.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Object Constraint Language.
CSCE 431: Interfaces and Contracts Some material from Bruegge, Dutoit.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Chapter 9: Object Design: Specifying Interfaces
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 5, Analysis: Dynamic Modeling.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 7, Object Design.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
Describing Syntax and Semantics
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Object Constraint Language.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Object Design  Object design  Detail requirements.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Using UML, Patterns, and Java Object-Oriented Software Engineering Example of a Problem Statement: Introduction into ARENA.
Object-Oriented Analysis and Design
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 4, Requirements Elicitation.
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.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
® IBM Software Group © 2006 IBM Corporation Rational Software France Object-Oriented Analysis and Design with UML2 and Rational Software Modeler 03. Classes,
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Object Constraint Language
1 Kyung Hee University Constraints Spring Kyung Hee University Graphical Notations  Graphical notations are well suited for displaying structural.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Relational Schema.
Chapter 2 Collections. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Define the concept and terminology related.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Chapter 16: UML Class Diagrams
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
CEN th Lecture Advance Software Engineering (CEN-5011) Instructor: Masoud Sadjadi Object Design: Specifying.
Object-Oriented Software Engineering Practical Software Development using UML and Java Modelling with Classes.
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
1 Use Cases Object-Oriented Modeling and Design with UML (Second Edition) Blaha & Rumbaugh Sections 7.1, 8.1.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Chapter 8, Object Design: Object Constraint Language
Chapter 9, Object Design: Specifying Interfaces
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Chapter 9, Object Design: Object Constraint Language
Chapter 9, Object Design: Object Constraint Language
CSCE 606: Interfaces and Contracts
Chapter 9, Object Design: Specifying Interfaces
Chapter 9, Object Design: Specifying Interfaces
Specifying Object Interfaces
Chapter 9, Object Design: Specifying Interfaces
Seminar 3 UML Class Diagram.
Call Class Class User Realize Class Developer Class Implementor
Object Design Object design is the process of adding details to the requirements analysis and making implementation decisions The object designer must.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Object Oriented System Design Class Diagrams
Object Constraint Language (OCL)
Formal Methods in Software Engineering 1
Presentation transcript:

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Few comments about midterm I graded very lightly & granted partial credits liberally Min: 25.5; Max: 98; Avg: 67; StDeviation: 14

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2 But … Some people still don’t know the difference between operations and objects A few people had no classes in class diagram! A few people had no objects/classes in sequence diagram Many people didn’t have boundary/control/entity objects in either Many people still don’t know the difference between >/ > relations and kind- of/part-of hierarchies Therefore: I will likely ask for a UML diagram (use, sequence, class) again in the final worth points and will give no partial credits.

Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4 Requirements Analysis vs. Object Design Requirements Analysis: The functional model and the dynamic model deliver operations for the object model Object Design: Decide where to put these operations in the object model Object design is the process of adding details to the requirements analysis making implementation decisions Thus, object design serves as the basis of implementation The object designer can choose among different ways to implement the system model obtained during requirements analysis.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5 Object Design: Closing the Final Gap Custom objects Application objects Off-the-shelf components Solution objects System Problem Machine System design gap Object design gap Requirements gap

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6 Developers play 3 different Roles during Object Design of a Class DeveloperClass Implementor Class User Class Extender Call the Class Realize the Class (Implement it) Refine the Class (Implement a subclass)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7 Class User versus Class Extender GameTicTacToeChess LeagueTournament 1 * The developer responsible for the implementation of League is a class user of Game The developer responsible for the implementation of TicTacToe is a class extender of Game The Developer responsible for the implementation of Game is a class implementor

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8 Specifying Interfaces Requirements analysis activities Identify attributes and operations without specifying their types or their parameters Object design activities Add visibility information Add type signature information Add contracts.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9 Add Visibility Information Class user (“Public”): + Public attributes/operations can be accessed by any class Class implementor (“Private”): - Private attributes and operations can be accessed only by the class in which they are defined They cannot be accessed by subclasses or other classes Class extender (“Protected”): # Protected attributes/operations can be accessed by the class in which they are defined and by any descendent of the class. Developer Call Class Class Extender Class Implementor Class User Realize Class Refine Class

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10 Implementation of UML Visibility in Java public Tournament(League l, int maxNumPlayers) public int getMaxNumPlayers() {…}; public List getPlayers() {…}; public void acceptPlayer(Player p) {…}; public void removePlayer(Player p) {…}; public boolean isPlayerAccepted(Player p) {…}; Tournament - maxNumPlayers: int + acceptPlayer(p:Player) + removePlayer(p:Player) + getMaxNumPlayers():int + getPlayers(): List + isPlayerAccepted(p:Player):boolean public class Tournament { private int maxNumPlayers;

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11 Information Hiding Heuristics Carefully define the public interface for classes as well as subsystems For subsystems use a façade design pattern if possible Always apply the “Need to know” principle: Only if somebody needs to access the information, make it publicly possible Provide only well defined channels, so you always know the access The fewer details a class user has to know the easier the class can be changed the less likely they will be affected by any changes in the class implementation Trade-off: Information hiding vs. efficiency Accessing a private attribute might be too slow.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12 Add Type Signature Information Hashtable +put(key:Object,entry:Object) +get(key:Object):Object +remove(key:Object) +containsKey(key:Object):boolean +size():int -numElements:int Hashtable put() get() remove() containsKey() size() numElements:int Attributes and operations without visibility and type information are ok during requirementsanalysis During object design, we decide that the hash table can handle any type of keys, not only Strings.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13 Modeling Constraints with Contracts Example of constraints in Arena: An already registered player cannot be registered again The number of players in a tournament should not be more than maxNumPlayers One can only remove players that have been registered We model them with contracts. These constraints can now be modeled in UML since contracts can be written in OCL (object constraint language), which has been made part of the UML standard.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14 Contracts and Formal Specification A contract is an exact specification of the interface of an object Contracts enable the caller and the provider to share the same assumptions about the class A contract include three types of constraints: Invariant: A predicate that is always true for all instances of a class Precondition (“rights”): Must be true before an operation is invoked Postcondition (“obligation”): Must be true after an operation is invoked.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15 Formal Specification A contract is called a formal specification, if the invariants, rights and obligations in the contract are unambiguous.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16 Expressing Constraints in UML Models A constraint can also be depicted as a note attached to the constrained UML element by a dependency relationship. HashTable put(key,entry:Object) get(key):Object remove(key:Object) containsKey(key:Object):boolean size():int numElements:int > numElements >= 0 > !containsKey(key) > containsKey(key) > !containsKey(key) > get(key) == entry

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17 Or using OCL: Object Constraint Language Formal language for expressing constraints over a set of objects and their attributes Part of the UML standard Used to write constraints that cannot otherwise be expressed in a diagram Declarative No side effects No control flow Based on Sets and Multi Sets

Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Object Constraint Language

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19 OCL: Object Constraint Language Formal language for expressing constraints over a set of objects and their attributes Part of the UML standard Used to write constraints that cannot otherwise be expressed in a diagram Declarative No side effects No control flow Based on Sets and Multi Sets

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20 OCL Basic Concepts OCL expressions Return True or False Are evaluated in a specified context, either a class or an operation All constraints apply to all instances

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21 OCL Simple Predicates Example: context Tournament inv: self.getMaxNumPlayers() > 0 In English: “The maximum number of players in any tournament should be a positive number.” Notes: “self” denotes all instances of “Tournament” OCL uses the same dot notation as Java.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22 OCL Preconditions Example: context Tournament::acceptPlayer(p) pre: not self.isPlayerAccepted(p) In English: “The acceptPlayer(p) operation can only be invoked if player p has not yet been accepted in the tournament.” Notes: The context of a precondition is an operation isPlayerAccepted(p) is an operation defined by the class Tournament

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23 OCL Postconditions Example: context Tournament::acceptPlayer(p) post: self.getNumPlayers() = + 1 In English: “The number of accepted player in a tournament increases by one after the completion of acceptPlayer()” Notes: denotes the state of the tournament before the invocation of the operation. Self denotes the state of the tournament after the completion of the operation.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24 OCL Contract for acceptPlayer() in Tournament context Tournament::acceptPlayer(p) pre: not isPlayerAccepted(p) context Tournament::acceptPlayer(p) pre: getNumPlayers() < getMaxNumPlayers() context Tournament::acceptPlayer(p) post: isPlayerAccepted(p) context Tournament::acceptPlayer(p) post: getNumPlayers() + 1

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25 OCL Contract for removePlayer() in Tournament context Tournament::removePlayer(p) pre: isPlayerAccepted(p) context Tournament::removePlayer(p) post: not isPlayerAccepted(p) context Tournament::removePlayer(p) post: getNumPlayers() - 1

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26 Java Implementation of Tournament class (Contract as a set of JavaDoc comments) public class Tournament { /** The maximum number of players * is positive at all times. maxNumPlayers > 0 */ private int maxNumPlayers; /** The players List contains * references to Players who are * are registered with the * Tournament. */ private List players; /** Returns the current number of * players in the tournament. */ public int getNumPlayers() {…} /** Returns the maximum number of * players in the tournament. */ public int getMaxNumPlayers() {…} /** The acceptPlayer() operation * assumes that the specified * player has not been accepted * in the Tournament yet. !isPlayerAccepted(p) getNumPlayers()<maxNumPlayers isPlayerAccepted(p) getNumPlayers() = + 1 */ public void acceptPlayer (Player p) {…} /** The removePlayer() operation * assumes that the specified player * is currently in the Tournament. isPlayerAccepted(p) !isPlayerAccepted(p) getNumPlayers() = - 1 */ public void removePlayer(Player p) {…} }

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27 Constraints can involve more than one class How do we specify constraints on on a group of classes? Starting from a specific class in the UML class diagram, we navigate the associations in the class diagram to refer to the other classes and their properties (attributes and Operations).

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28 Example from ARENA: League, Tournament and Player players *tournaments {ordered} Tournament +start:Date +end:Date +acceptPlayer(p:Player) * League +start:Date +end:Date +getActivePlayers() * Player +name:String + String *players tournaments* Constraints: 1.A Tournament’s planned duration must be under one week. 2.Players can be accepted in a Tournament only if they are already registered with the corresponding League. 3.The number of active Players in a League are those that have taken part in at least one Tournament of the League.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29 Instance Diagram: 2 Leagues tttExpert:League chessNovice:League alice:Player bob:Player marc:Player joe:Player zoe:Player winter:Tournament start=Jan 12 end= Jan 14 Xmas:Tournament start=Dec 23 end= Dec 25, 5 Players, 2 Tournaments

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30 3 Types of Navigation through a Class Diagram 1. Local attribute2. Directly related class3. Indirectly related class Tournament League * * Player * League Player * * Tournament start:Date end:Date Any constraint for an arbitrary UML class diagram can be specified using only a combination of these 3 navigation types!

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31 Specifying the Model Constraints in OCL Local attribute navigation players *tournaments {ordered} Tournament +start:Date +end:Date +acceptPlayer(p:Player) * League +start:Date +end:Date +getActivePlayers() * Player +name:String + String *players tournaments* Directly related class navigation context Tournament inv: end - start <= 7 context Tournament::acceptPlayer(p) pre: league.players->includes(p)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32 OCL Sets, Bags and Sequences Sets, Bags and Sequences are predefined in OCL and subtypes of Collection. OCL offers a large number of predefined operations on collections. They are all of the form: collection->operation(arguments)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33 OCL-Collection The OCL-Type Collection is the generic superclass of a collection of objects of Type T Subclasses of Collection are Set: Set in the mathematical sense. Every element can appear only once Bag: A collection, in which elements can appear more than once (also called multiset) Sequence: A multiset, in which the elements are ordered Example for Collections: Set(Integer): a set of integer numbers Bag(Person): a multiset of persons Sequence(Customer): a sequence of customers

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34 OCL-Operations for OCL-Collections (1) size: Integer Number of elements in the collection includes(o:OclAny): Boolean True, if the element o is in the collection count(o:OclAny): Integer Counts how many times an element is contained in the collection isEmpty: Boolean True, if the collection is empty notEmpty: Boolean True, if the collection is not empty The OCL-Type OclAny is the most general OCL-Type

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35 OCL-Operations for OCL-Collections(2) union(c1:Collection) Union with collection c1 intersection(c2:Collection) Intersection with Collection c2 (contains only elements, which appear in the collection as well as in collection c2 auftreten) including(o:OclAny) Collection containing all elements of the Collection and element o select(expr:OclExpression) Subset of all elements of the collection, for which the OCL- expression expr is true

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36 How do we get OCL-Collections? A collection can be generated by explicitly enumerating the elements A collection can be generated by navigating along one or more 1-N associations Navigation along a single 1:n association yields a Set Navigation along a couple of 1:n associations yields a Bag (Multiset) Navigation along a single 1:n association labeled with the constraint {ordered } yields a Sequence

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37 Navigation through a 1:n-Association Example: A Customer should not have more than 4 cards context Customer inv: card->size <= 4 Alternative writing style Customer card->size <= 4 name: String titel: String age: Integer birthday: Date getage(): Integer Customer valid: Boolean validSince: Date expires: Date color: enum { silver, gold} printedName : String customerCard owner card * card denotes a set of customercards

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38 Navigation through several 1:n-Associations Example: programPartner nrcustomer = bonusprogram.customer->size nrcustomer: Integer programPartner name: String titel: String age: Integer birthday: Datum getage(): Integer Customer 1..* register(k:Customer) Bonusprogram program *.* Customer denotes a multiset of customer bonusprogram denotes a set of Bonusprograms

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39 Navigation through a constrained Association Navigation through an association with the constraint {ordered} yields a sequence. Example: Bonusprogram level->size = 2 register(k: Customer) Bonusprogram {ordered} name: String Level * level denotes a sequence of levels

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40 Conversion between OCL-Collections OCL offers operations to convert OCL-Collections: asSet Transforms a multiset or sequence into a set asBag transforms a set or sequence into a multiset asSequence transforms a set or multiset into a sequence.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41 Example of a Conversion programPartner nrcustomer = bonusprogram.Customer->size This expression may contain customer multiple times, we can get the number of unique customers as follows: programPartner nrcustomer = bonusprogram.Customer->asSet->size nrcustomer: Integer programPartner name: String titel: String age: Integer birthday: Datum getage(): Integer Customer 1..* register(k:Customer) Bonusprogram program *.*

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42 Operations on OCL-Type Sequence first: T The first element of a sequence last: T The last element of a sequence at(index:Integer): T The element with index index in the sequence Example: „The first Level, you can reach in the bonusprogram has the name 'Silber'." OCL-Invariant: Bonusprogram: level->first.name = "Silber"

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43 Specifying the Model Constraints: Using asSet Local attribute navigation context Tournament inv: end - start <= Calendar.WEEK Directly related class navigation context Tournament::acceptPlayer(p) pre: league.players->includes(p) players *tournaments {ordered} Tournament +start:Date +end:Date +acceptPlayer(p:Player) * League +start:Date +end:Date +getActivePlayers() * Player +name:String + String *players tournaments* Indirectly related class navigation context League::getActivePlayers post: result=tournaments.players->asSet

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44 Evaluating OCL Expressions The value of an OCL expression is an object or a collection of objects. Multiplicity of the association-end is 1 The value of the OCL expression is a single object Multiplicity is 0..1 The result is an empty set if there is no object, otherwise a single object Multiplicity of the association-end is * The result is a collection of objects By default, the navigation result is a Set When the association is {ordered}, the navigation results in a Sequence Multiple “1-Many” associations result in a Bag

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45 Summary Constraints are predicates (often boolean expressions) on UML model elements Contracts are constraints on a class that enable class users, implementors and extenders to share the same assumption about the class (“Design by contract”) OCL is the example of a formal language that allows us to express constraints on UML models Complicated constrains involving more than one class, attribute or operation can be expressed with 3 basic navigation types.