ch09lect2_UD - Using UML Patterns and Java Object-Oriented...

Info icon This 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
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
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
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.
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
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.
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) context  Tournament::acceptPlayer(p)  pre : getNumPlayers() < getMaxNumPlayers() context  Tournament::acceptPlayer(p)  post : isPlayerAccepted(p) context  Tournament::acceptPlayer(p)  post : getNumPlayers() = @pre.getNumPlayers() + 1
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) 
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern