111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, 1990. (Chapter 8) Meyer, B., Applying design by contract,

Slides:



Advertisements
Similar presentations
11 Contracts CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 6)
Advertisements

Karlstad University Computer Science Design Contracts and Error Management Design Contracts and Errors A Software Development Strategy Eivind J. Nordby.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Jan 23, Ron McFadyen1 SSD for a samplePOS Use Case Figure 13.1 Input Events invoke a system operation of the same name same idea as in object-oriented.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
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
NJIT Use Case Model Operation Contracts Prepared By: Sumit Sharma.
© 2005 Prentice Hall4-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
CHAPTER 3 COLLECTIONS SET Collection. 2 Abstract Data Types A data type consists of a set of values or elements, called its domain, and a set of operators.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
September 2002 R McFadyen1 Domain Model Use Case Model text diagram SSD System operation contracts Design Model Figure 13.3.
Object Specification Moving towards a more precise specification of software.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Topic 3 The Stack ADT.
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Chapter 9 Formal Specifications.
TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
Use Case Model Operation Contracts Chapter 11 Applying UML and Patterns Craig Larman.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
CS Collaborations and Hierarchies CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object- Oriented Software,
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
An Ontological Framework for Web Service Processes By Claus Pahl and Ronan Barrett.
CSE 373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
© 2005 Prentice Hall9-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
CS Collaborations and Hierarchies CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object- Oriented Software,
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
DOMAIN MODEL: ADDING ATTRIBUTES Identify attributes in a domain model. Distinguish between correct and incorrect attributes.
Data Structures & Algorithms
Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract,
Computer Science 209 Software Development Handing Errors and Creating Documentation.
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
Data Structures: CSCI Chapter 1 Data Structures: CSCI Chapter 1 lecture notes adapted from Data Structures with C++ using STL Dr. Nazli Mollah.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Lab 6 Stack ADT. OVERVIEW The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
Domain Model A representation of real-world conceptual classes in a problem domain. The core of object-oriented analysis They are NOT software objects.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Linked Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Used to help understand requirements more completely
Collaborations and Hierarchies
About the Presentations
Specifications What? Not how!.
Preconditions, Postconditions & Assertions
Specifying Object Interfaces
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
Slides by Steve Armstrong LeTourneau University Longview, TX
COMPUTER 2430 Object Oriented Programming and Data Structures I
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Introduction to Data Structure
Stacks Chapter 5.
Algebraic Specification Software Specification Lecture 34
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
A type is a collection of values
Presentation transcript:

111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer, 25(10):40-51, October 1992.

222 Outline Protocols: what and why? Documenting protocols Process and guidelines

Review Responsibility? Contract? 3

Definitions Signature: method name, input and output parameters and their types, and return type Protocol: set of signatures for methods to be implemented 4

Why Write Protocols? Define an interface to a class. (Why?) 5

Protocol Structure Signature  Method name  Type of return value  Type of input and output parameters  Description of input, output, input-output parameters Purpose Pre-condition Post-condition 6

Notation Signature, a.k.a. syntactic interface  Language neutral declaration, e.g., UML and CRC draw(in g: Graphics): void  Language-specific declaration, e.g., Java and C++ void draw(Graphics g)  Strength and weakness? 7

Notation (Cont.) Behavior, a.k.a. semantic interface  Informal description or stylized texts Example: Given a non-empty list of integers, determine if it is sorted.  Formal descriptions, e.g., OCL and Design-by- Contract notations pre: not c->isEmpty() post: c->incldues(result) and c->forAll(e: Integer | result >= e)  Strength and weakness? 8

Specifying Classes Class: Drawing Superclasses: DisplayableObject Subclasses: None Class Diagram: see Figure 2-1 Collaborations Diagram: see Figure 3-5 Description: Represents the structure of the elements … Contracts 2. Maintain the elements in a drawing Know which elements are contained in the drawing addElement(DrawingElement) uses List Adds a drawing element to the front of the list of drawing elements. Pre: The element is not already contained in the list. Post: The element is the first element of the list. 9

Specifying Classes (Cont.) elementAt(Point) returns DrawingElement uses List, DrawingElement (3) Returns the drawing element at the given point. Pre: none Post: if boundary rectangle contains Point then returned is the first such drawing element in List else returned is a null object Maintain the ordering between elements elementAfter(DrawingElement) returns DrawingElement uses List … 10

Pre-condition Capture the conditions that must be true before the method executes Describe the required state of the ADT or object before entering the function Written as an expression that is true or false May consist of expressions connected by logical operators (AND, OR) Use true when no pre-condition exists 11

Post-condition Must clearly state what is true when the method completes execution Describe the expected state upon exiting the function Should be strong enough so that only correct implementations will satisfy the condition 12

What’s the Value of Pre- and Post- conditions? (Pair) 2 minutes 13

Process for Writing Protocols For each class For each contract For each responsibility Specify complete protocol (set of signatures) to support the responsibility 14

Guidelines: Names Use single name for single conceptual operation, regardless of where it is found  E.g., add vs. insert, remove vs. delete, contains vs. has vs. includes for collections Associate a single conceptual aspect with each method name 15

Guidelines: Generality Make protocols as generally useful as possible  The more general a responsibility, the more messages needed to support it.  E.g., size vs. enumerating elements for collections 16

Guidelines: Default Values Define reasonable defaults  Provide most general message: user specifies all possible parameters  Provide defaults for any parameter for which it is reasonable  Let client specify subset of parameters 17

Example display() display(device) display(region) display(device, region) display(device, region, rule) display(device, region, rule, transform) 18

Exercise Make the indexOf method of String more general and reusable. /** Returns the index of the first occurrence of the given character. */ int indexOf(int ch) (Pair) 2 minutes 19

Guidelines: Pre and Post State as assertions not as actions.  Why?  E.g., int String.indexOf(int c) pre: none post: if c appears in this string then return the index of the first occurrence else return -1 post: if c appears in this string then result is the index of the first occurrence of c else result is -1 post: result is the index of the first occurrence if c appears in this string; otherwise it is -1 20

Guidelines: Rework, rework, … Generate protocols for main responsibilities  Protocols to public methods must be unambiguous since it is the interface with clients  Protocols to private methods are notes to developer Common to discover holes in design at this point Repeat earlier phases of design 21

Example: ADT Stack Additions are restricted to one end identified as the top of the stack. Deletions are restricted to the top of the stack. Only the item at the top of the stack is accessible A stack is often referred to as a LIFO (Last In First Out) list. 22

In-class Identify operations for Stack (Pair) 2 minutes 23

In-class Specify protocols for isEmpty() and pop() (Pair) 5 minutes 24

In-class (Pairs) Consider a class, say Contact Manager, that manage a contacts list, where a contact contains contact information such as name, phone number, address, etc.  Identify responsibilities for Contact Manager  Define protocols for adding and search operations/responsibilities. 25