ch09lect2_UD - Object-Oriented Software Engineering Using...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Object Constraint Language
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 2 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
Background image of page 2
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3 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
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4 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.
Background image of page 4
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5 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
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6 OCL Postconditions Example: context Tournament::acceptPlayer(p) post : self.getNumPlayers() = [email protected]() + 1 In English: “The number of accepted player in a tournament  increases by one after the completion of  acceptPlayer()” Notes: [email protected] 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.
Background image of page 6
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 7 OCL Contract for acceptPlayer() in   Tournament context Tournament::acceptPlayer(p) pre: not isPlayerAccepted(p) getNumPlayers() < getMaxNumPlayers() context Tournament::acceptPlayer(p) post: isPlayerAccepted(p) getNumPlayers() = @pre.getNumPlayers() + 1
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 8 OCL Contract for removePlayer()  in  Tournament context Tournament::removePlayer(p) pre: isPlayerAccepted(p) context Tournament::removePlayer(p) post: not isPlayerAccepted(p) getNumPlayers() = @pre.getNumPlayers() - 1
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 28

ch09lect2_UD - Object-Oriented Software Engineering Using...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online