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 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 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.
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;
NJIT Use Case Model Operation Contracts Prepared By: Sumit Sharma.
Chapter 7, Object Design.
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.
September 2002 R McFadyen1 Domain Model Use Case Model text diagram SSD System operation contracts Design Model Figure 13.3.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Object Design  Object design  Detail requirements.
Sept Ron McFadyen1 Extend Relationship.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Writing Classes (Chapter 4)
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part V: Design The Design Workflow Design Classes Refining Analysis Relationships.
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 8, Object Design: Reusing Pattern Solutions.
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.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
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.
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
CEN th Lecture Advance Software Engineering (CEN-5011) Instructor: Masoud Sadjadi Object Design: Specifying.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 9, Object Design: Specifying Interfaces
Used to help understand requirements more completely
Chapter 16 UML Class Diagrams.
Example of a Problem Statement: Introduction into ARENA
Inheritance and Polymorphism
Chapter 11 Object-Oriented Design
Design Class Diagrams
TIM 58 Chapter 8: Class and Method Design
Chapter 9, Object Design: Object Constraint Language
Example of a Problem Statement: Introduction into ARENA
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Chapter 9, Object Design: Specifying Interfaces
Specifying Object Interfaces
Chapter 9, Object Design: Specifying Interfaces
Corresponds with Chapter 7
Inheritance, Polymorphism, and Interfaces. Oh My
Example of a Problem Statement: Introduction into ARENA
Slides by Steve Armstrong LeTourneau University Longview, TX
Call Class Class User Realize Class Developer Class Implementor
CIS 375 Bruce R. Maxim UM-Dearborn
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,
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Introduction to Data Structure
Chapter 9 Carrano Chapter 10 Small Java
Defining Classes and Methods
CIS 375 Bruce R. Maxim UM-Dearborn
Object Constraint Language (OCL)
Presentation transcript:

Chapter 9, Object Design: Specifying Interfaces

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. 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

Object Design: Closing the Final Gap System Problem Application objects Requirements gap Solution objects Object design gap Custom objects Off-the-shelf components System design gap Machine

Developers play 3 different Roles during Object Design of a Class Class User Call the Class Developer Class Implementor Realize the Class (Implement it) Class Extender Refine the Class (Implement a subclass)

Class User versus Class Extender The Developer responsible for the implementation of Game is a class implementor The developer responsible for the implementation of League is a class user of Game League Game 1 * TicTacToe Chess Tournament The developer responsible for the implementation of TicTacToe is a class extender of Game

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. A constraint is a restriction on the degree of freedom you have in providing a solution (Leffingwell & Widrig 2000). Constraints are effectively nonfunctional requirements, such as limited development resources or a decision by senior management that restricts the way you develop a system

Add Visibility Information Developer Call Class Class Extender Class Implementor Class User Realize Class Refine Class Class user (“Public”): + Public attributes/operation 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. 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 by any descendent of the class. + Public => Class user: A public attribute or operation can be accessed by any class.

Implementation of UML Visibility in Java Tournament - maxNumPlayers: int + acceptPlayer(p:Player) + removePlayer(p:Player) + getMaxNumPlayers():int + getPlayers(): List + isPlayerAccepted(p:Player):boolean public class Tournament { private int maxNumPlayers; 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) {…};

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. Information hiding is not a major issue during analysis, however during design it is a problem. Limit the effect of changes so that changes can be understood clearly and do not cause a major recompilation of the whole system (also called black box design) Accessing a private attribute might be too slow (for example in real-time systems or games)

Add Type Signature Information Hashtable put() get() remove() containsKey() size() numElements:int Attributes and operations without visibility and type information are ok during requirementsanalysis Hashtable +put(key:Object,entry:Object) +get(key:Object):Object +remove(key:Object) +containsKey(key:Object):boolean +size():int -numElements:int During object design, we decide that the hash table can handle any type of keys, not only Strings.

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 contacts can be written in OCL, which has been made part of the UML standard.

Contracts and Formal Specification Contracts enable the caller and the provider to share the same assumptions about the class A contract is an exact specification of the interface of an object 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. Contracts enable the caller and provider to share the same assumptions about the class. A contract is an exact specification of the interface of an object. A contract 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 (“rights”): Preconditions are predicates associated with a specific operation and must be true before the operation is invoked. Postcondition (“oblicgation”): Postconditions are predicates associated with a specific operation and must be true after an operation is invoked. If the invariants, rights and oblications in the contract are unambigious, the contract is called a formal specification Preconditions are used to specify constraints that a caller must meet before calling an operation. Postconditions are used to specify constraints that the object must ensure after the invocation of the operation.

Formal Specification A contract is called a formal specification, if the invariants, rights and obligations in the contract are unambiguous.

Expressing Constraints in UML Models A constraint can also be depicted as a note attached to the constrained UML element by a dependency relationship. <<invariant>> numElements >= 0 <<precondition>> !containsKey(key) HashTable put(key,entry:Object) get(key):Object remove(key:Object) containsKey(key:Object):boolean size():int numElements:int <<postcondition>> get(key) == entry <<precondition>> containsKey(key) <<postcondition>> !containsKey(key) <<precondition>> containsKey(key)

Expressing Constraints in UML Models A constraint can also be depicted as a note attached to the constrained UML element by a dependency relationship. <<invariant>> numElements >= 0 <<precondition>> !containsKey(key) HashTable put(key,entry:Object) get(key):Object remove(key:Object) containsKey(key:Object):boolean size():int numElements:int <<postcondition>> get(key) == entry <<precondition>> containsKey(key) <<postcondition>> !containsKey(key) <<precondition>> containsKey(key)

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