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

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 4, Requirements Elicitation.
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.
Using UML, Patterns, and Java Object-Oriented Software Engineering Royce’s Methodology Chapter 16, Royce’ Methodology.
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.
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.
Chapter 6: Using Design Patterns
Chapter 9: Object Design: Specifying Interfaces
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
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.
Software Testing and Quality Assurance
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Art for Chapter 9, Testing.
Chapter 7, Object Design.
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.
September 2002 R McFadyen1 Domain Model Use Case Model text diagram SSD System operation contracts Design Model Figure 13.3.
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.
Blaha and Rumbaugh Sections 7.2 and 8.2
Object-Oriented Analysis and Design
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Advance Information Systems Development (SD3043) Lecture 3: Requirements Elicitation / Analysis/Design Dr. Haris Mouratidis 10 th October.
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.
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 10, Mapping Models to Code.
Systems Analysis and Design in a Changing World, 3rd Edition
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
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 1 Few comments about midterm I graded very lightly.
CSC 480 Software Engineering Design by Contract. Detail Design Road Map Begin with architectural models  Class model: domain classes  Overall state.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Relational Schema.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
CEN th Lecture Advance Software Engineering (CEN-5011) Instructor: Masoud Sadjadi Object Design: Specifying.
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.
Why is Design so Difficult? Analysis: Focuses on the application domain Design: Focuses on the solution domain –The solution domain is changing very rapidly.
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
Used to help understand requirements more completely
Example of a Problem Statement: Introduction into ARENA
Chapter 9, Object Design: Object Constraint Language
Chapter 10, Mapping Models to Code
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
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.
Presentation transcript:

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

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 2 Object Design  Object design is the process of adding details to the requirements analysis and making implementation decisions  The object designer must choose among different ways to implement the analysis model with the goal to minimize execution time, memory and other measures of cost.  Requirements Analysis: The functional model and the dynamic model deliver operations for the object model  Object Design: We decide on where to put these operations in the object model  Object design serves as the basis of implementation

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3 Developers play different Roles during Object Design 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 4 Class user versus Class Extender GameTicTacToeChess LeagueTournament 1 * Developers responsible for the implementation of League are class users of Game The developer responsible for the implementation of TicTacToe is a class extender of Game Developers responsible for the implementation of Game are class implementors

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5 Specifying Interfaces  Requirements analysis activities  Identifying attributes and operations without specifying their types or their parameters.  Object design: Three activities 1. Add visibility information 2. Add type signature information 3. Add contracts

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6 1. Add Visibility Information UML defines three levels of visibility:  Private (Class implementor):  A private attribute can be accessed only by the class in which it is defined.  A private operation can be invoked only by the class in which it is defined.  Private attributes and operations cannot be accessed by subclasses or other classes.  Protected (Class extender):  A protected attribute or operation can be accessed by the class in which it is defined and on any descendent of the class.  Public (Class user):  A public attribute or operation can be accessed by any class.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 7 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 Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 8 Information Hiding Heuristics  Carefully define the public interface for classes as well as subsystems (façade)  Always apply the “Need to know” principle.  Only if somebody needs to access the information, make it publicly possible, but then only through well defined channels, so you always know the access.  The fewer an operation knows  the less likely it will be affected by any changes  the easier the class can be changed  Trade-off: Information hiding vs efficiency  Accessing a private attribute might be too slow (for example in real-time systems or games)

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 9 Information Hiding Design Principles  Only the operations of a class are allowed to manipulate its attributes  Access attributes only via operations.  Do not apply an operation to the result of another operation.  Write a new operation that combines the two operations.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 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 type information are acceptable during analysis

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems Add Contracts  Contracts on a class enable caller and callee to share the same assumptions about the class.  Contracts include three types of constraints:  Invariant:  A predicate that is always true for all instances of a class. Invariants are constraints associated with classes or interfaces.  Precondition:  Preconditions are predicates associated with a specific operation and must be true before the operation is invoked. Preconditions are used to specify constraints that a caller must meet before calling an operation.  Postcondition:  Postconditions are predicates associated with a specific operation and must be true after an operation is invoked. Postconditions are used to specify constraints that the object must ensure after the invocation of the operation.

Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 12 Expressing constraints in UML Models  OCL (Object Constraint Language)  OCL allows constraints to be formally specified on single model elements or groups of model elements  A constraint is expressed as an OCL expression returning the value true or false. OCL is not a procedural language (cannot constrain control flow).  OCL expressions for Hashtable operation put():  Invariant:  context Hashtable inv: numElements >= 0 OCL expression Context is a class operation put  Precondition:  context Hashtable::put(key, entry) pre:!containsKey(key)  Post-condition:  context Hashtable::put(key, entry) post: containsKey(key) and get(key) = entry

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

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14 Contract for acceptPlayer in Tournament (textual description of contracts, out of UML diagram) 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 15 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 16 Annotation of Tournament class 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 17 Constraints can involve more than one class How do we specify constraints on more than one class?

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

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19 ARENA Example: 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*

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20 Model Refinement with 3 additional Constraints  A Tournament’s planned duration must be under one week.  Players can be accepted in a Tournament only if they are already registered with the corresponding League.  The number of active Players in a League are those that have taken part in at least one Tournament of the League.  To better understand these constraints we instantiate the class diagram for a specific group of instances  2 Leagues, 2 Tournaments and 5 Players

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

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

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23 La cardinalità molti potrebbe dare luogo a ripetizioni dei valori di player per questo bisogna convertire in Set Specifying the Model Constraints (see Slide 20) Local attribute navigation context Tournament inv: end - start <= Calendar.WEEK Directly related class navigation context Tournament::acceptPlayer(p) pre: league.players->includes(p) Indirectly related class navigation context League::getActivePlayers post: result = tournaments.players->asSet players *tournaments {ordered} Tournament +start:Date +end:Date +acceptPlayer(p:Player) * League +start:Date +end:Date +getActivePlayers() * Player +name:String + String *players tournaments*

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24 OCL supports Quantification  OCL forall quantifier /* All Matches in a Tournament occur within the Tournament’s time frame */ context Tournament inv: matches->forAll(m:Match | m.start.after(t.start) and m.end.before(t.end))  OCL exists quantifier /* Each Tournament conducts at least one Match on the first day of the Tournament */ context Tournament inv: matches->exists(m:Match | m.start.equals(start))

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25 Summary  There are three different roles for developers during object design  Class user, class implementor and class extender  During object design - and only during object design - we specify visibility rules  Constraints are boolean expressions on model elements  Contracts are constraints on a class enable class users, implementors and extenders to share the same assumption about the class (“Design by contract”)  OCL is a language that allows us to express constraints on UML models  Complicated constratins involving more than one class, attribute or operation can be expressed with 3 basic navigation types.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26 Additional Slides

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27 ARENA’s object model identified during the analysis TournamentControl Player players* Tournament name 1 1 applyForTournament() Match playMove() getScore() matches * start status selectSponsors() advertizeTournament() acceptPlayer() announceTournament() start end 1 1 * matches * TournamentForm * * acceptPlayer() removePlayer() schedule() Advertiser sponsors* * * * *

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28 Adding type information to ARENA’s object model TournamentControl Player players* Tournament 1 1 +applyForTournament() Match +playMove(p,m) +getScore():Map matches * +start:Date +status:MatchStatus +name:String +start:Date +end:Date 1 1 * matches* TournamentForm * * +acceptPlayer(p) +removePlayer(p) +schedule() Advertiser sponsors* * * * * +selectSponsors(advertisers):List +advertizeTournament() +acceptPlayer(p) +announceTournament() +isPlayerOverbooked():boolean

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29 Pre- and post-conditions for ordering operations on TournamentControl context TournamentControl::selectSponsors(advertisers) pre: interestedSponsors->notEmpty and tournament.sponsors->isEmpty context TournamentControl::selectSponsors(advertisers) post: tournament.sponsors.equals(advertisers) context TournamentControl::advertiseTournament() pre: tournament.sponsors->isEmpty and not tournament.advertised context TournamentControl::advertiseTournament() post: tournament.advertised context TournamentControl::acceptPlayer(p) pre: tournament.advertised and interestedPlayers->includes(p) and not isPlayerOverbooked(p) context TournamentControl::acceptPlayer(p) post: tournament.players->includes(p) TournamentControl +selectSponsors(advertisers):List +advertizeTournament() +acceptPlayer(p) +announceTournament() +isPlayerOverbooked():boolean

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30 Specifying invariants on Tournament and Tournament Control  All Matches of in a Tournament must occur within the time frame of the Tournament context Tournament inv: matches->forAll(m| m.start.after(start) and m.start.before(end))  No Player can take part in two or more Tournaments that overlap context TournamentControl inv: tournament.players->forAll(p| p.tournaments->forAll(t| t <> tournament implies not t.overlap(tournament)))

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31 Specifying invariants on Match  A match can only involve players who are accepted in the tournament context Match inv: players->forAll(p| p.tournaments->exists(t| t.matches->includes(self))) context Match inv: players.tournaments.matches.includes(self) Player players * Tournament Match matches * * tournaments players *