Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, 1990. Mitchell, R., and McKim, Design by Contract,

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

Lab 8 Ordered list. OVERVIEW In an ordered list the elements are maintained in ascending (or descending) order based on the data contained in the list.
Karlstad University Computer Science Design Contracts and Error Management Design Contracts and Errors A Software Development Strategy Eivind J. Nordby.
© SERG Dependable Software Systems (OO Protocol Testing) Dependable Software Systems Testing the Protocols of Classes in Object-Oriented Programs Material.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Copyright W. Howden1 Lecture 13: Programming by Contract.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
1 CSCD 326 Data Structures I Stacks. 2 Data Type Stack Most basic property: last item in (most recently inserted) is first item out LIFO - last in first.
Stacks.
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.
Chapter 1 Principles of Programming and Software Engineering.
Chapter 1 Software Engineering. Homework ► Read Section 2.2 (pages 79-98) ► Answer questions: ► 7, 8, 11, 12, & 13 on page 134. ► Answer on paper, hand.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
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.
Ranga Rodrigo. Class is central to object oriented programming.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
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.
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.
1 Stacks. 2 A stack has the property that the last item placed on the stack will be the first item removed Commonly referred to as last-in, first-out,
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
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.
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
CSC 480 Software Engineering Design by Contract. Detail Design Road Map Begin with architectural models  Class model: domain classes  Overall state.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Data Structures Using C++ 2E
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Week 3: Requirement Analysis & specification
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
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.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
Chapter 2 Principles of Programming and Software Engineering.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Laurea Triennale in Informatica – Corso di Ingegneria del Software I – A.A. 2006/2007 Andrea Polini IX. System Models (III)
Class Invariants Class invariants are logical conditions to ensure the correct working of a class. Class invariants must hold true when an object is created,
CC 215 Data Structures Queue ADT
Principles of Programming and Software Engineering
Stacks and Queues.
About the Presentations
Specifications What? Not how!.
Java Programming: Guided Learning with Early Objects
Preconditions, Postconditions & Assertions
Specifying Object Interfaces
Introduction to Data Structures
Slides by Steve Armstrong LeTourneau University Longview, TX
COMPUTER 2430 Object Oriented Programming and Data Structures I
Data Structures and Algorithms for Information Processing
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Pointers & Dynamic Data Structures
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
CMPT 225 Lecture 8 – Queue.
Presentation transcript:

Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract, by Example, Addison-Wesley, 2002 La Trobe University, Data Structure, latrobe.edu.au/courses/subjects/DataStructures/mal/session070/le cture.htmlhttp://ironbark.bendigo

2 Goals of Protocols Refine design – –Associate one or more methods (procedures) with each responsibility Define protocols –Protocols set of signatures for methods to be implemented –Signatures method name, input and output parameters, and return type

3 Importance of Protocols Delegate implementation to programmers –Specialization of personnel (analyst, designer, programmer) Program understanding –Maintenance Test Cases –Derive test cases from pre and post conditions Documentation –

4 Protocol Structure Signature –Method name –Type of input and output parameters –Description of input, output, input-output parameters –Description of internal data structures Purpose Pre-conditions// require Post-conditions// ensure Uses

5 Properties All ADTs and objects possess properties (behavioral rules). Properties can be stated using a set of Pre- and Post-conditions for each method. Properties can be stated using a set of invariants for each object or ADT. Good software engineering practice recommends that you to state Pre- and Post-conditions for all methods.

6 Pre- and Post-conditions Provide a set of conditions (a contract) that the implementer of the method must meet Help the reader to know what they can expect of the method

7 Pre-conditions 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 a statement that is true or false May consist of statements connected by logical operators (AND, OR) Can be written formally or informally

8 Post-conditions Must clearly state what is true when the method completes execution Should be strong enough so that only correct implementations will satisfy the condition

9 Notes Generate protocols for main responsibilities –Protocols to public methods must be unambiguous Why? – Common to discover holes in design at this point Repeat earlier phases of design

10 Example: ADT Stack -1 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 FILO (First In Last Out) list.

11 Example: ADT Stack -2 Public operations –Initialize – –Pop –IsEmpty –IsFull –Length

12 Example: ADT Stack -3 IsEmpty() : boolean –PRE: –POST: The stack is unchanged

13 Example: ADT Stack -4 pop (): object –PRE: –POST: If stack is not empty, then return the item from the top of the stack The length of the stack at the end of the operation is one less than the length of the stack at the start of the operation If stack length is greater than one, then the top of the stack is repositioned to the penultimate item in the stack. The remainder of the stack is unchanged.

14 Example: ADT Stack -4 (revisted) pop (): object –PRE: –POST: (If stack is not empty, then (the item from the top of the stack is returned AND the length of the stack at the end of the operation is one less than the length of the stack at the start of the operation AND the remainder of the stack is unchanged)) AND If stack length is greater than one at the start of the operation, then the top of the stack is repositioned to the penultimate item in the stack.

15 Example: ADT Stack -5 push (IN: item) : void –PRE: The stack has been initialized and the stack is not full. item contains valid data. –POST: The top of the stack contains the object passed in as item. The remainder of the stack is unchanged. The stack is not empty.

16 Example: ADT Stack -6 Robustness push (IN: item) : void –//Adding to the stack PRE: // relaxing preconditions The stack has been initialized. –POST: The size of the stack is incremented by one. The top of the stack contains the object passed in as item. The remainder of the stack is unchanged. The stack is not empty. –Error conditions: If the stack is full, then display error message AND do not change the ADT state If item does not contain valid data, then display error message AND do not change the ADT state

17 Specifying Protocols Include in Detailed Design section of SDD For each subsystem, group documentation of classes as follows: Class: Superclasses: || none Subclasses: || none Collaboration Graphs: See Figure Description: Contracts: Private variables: [… ] || none See handout for method template

18 Exercise: ADT List List (void); bool isin (int item); void print (void); void count (void); void print_reverse (void); void insert (int item); void delete(int item); Write the description and pre- and post- conditions for the following methods: