ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.

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

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Design by Contract.
Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Carlos D. Rivera February 28, 2007 Design-by-Contract.
Data Abstraction II SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Software Engineering and Design Principles Chapter 1.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
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.
Software Testing and Quality Assurance
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Exceptions David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 The Role of Exceptions Definition: a method succeeds if it terminates in.
Department of Computer Science University of Maryland, College Park
Improved software quality through semantic descriptions (Skutt) Karlstad University Dept. of Computer Science Semla Design Method for use in.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Karlstad University Computer Science Design Contracts and Error Management Design Contracts and Errors A Software Development Strategy (anpassad för PUMA)
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Eiffel Language and Design by Contract Contract –An agreement between the client and the supplier Characteristics –Expects some benefits and is prepared.
1 © Wolfgang Pelz Design by Contract Design by Contract™ Based on material drawn from: Bertrand.
Object-Oriented Analysis and Design
Computer Science 340 Software Design & Testing Design By Contract.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Ranga Rodrigo. Class is central to object oriented programming.
The Pseudocode Programming Process Chapter 9. Summary of Steps in Building Classes and Routines.
SE-280 Dr. Mark L. Hornick Design Review Issues. SE-280 Dr. Mark L. Hornick 2 Many expensive defects are a result of design problems Software applications.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
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.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
THE DESIGN WORKFLOW  Object-oriented design  The design workflow  The test workflow: Design  CASE tools for design  Challenges of the design workflow.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
© Paul Ammann, 2008 Design by Contract Paul Ammann CS/SWE 332.
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.
Computer Science 209 Software Development Handing Errors and Creating Documentation.
PC204 Lecture 5 Programming Methodologies Copyright 2000 by Conrad Huang and the Regents of the University of California. All rights reserved.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Loop Invariants and Binary Search Chapter 4.4, 5.1.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
1 Exceptions When the Contract is Broken. 2 Definitions A routine call succeeds if it terminates its execution in a state satisfying its contract A routine.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
CSCE 240 – Intro to Software Engineering Lecture 3.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Used to help understand requirements more completely
Topics: jGRASP editor ideosyncrasies assert debugger.
The Pseudocode Programming Process
Specifying Object Interfaces
Programming Languages 2nd edition Tucker and Noonan
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
CSE 303 Concepts and Tools for Software Development
Defining Classes and Methods
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Computer Science 340 Software Design & Testing
ENERGY 211 / CME 211 Lecture 27 November 21, 2008.
Software Specifications
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed design. Good enough that you can let someone else implement it. This is very hard to do well! Topics : Interfaces Contracts Pseudocode

ANU COMP2110 Software Design in 2003 Lecture 10Slide 2 1. Interfaces This is not the Java interface concept – a purely abstract class with no implementation This is also not about user interfaces – more on them in some later lectures This is about documenting the way a software component interacts with other components We will cover both classes and routines

ANU COMP2110 Software Design in 2003 Lecture 10Slide 3 Class interfaces List all public (externally visible) features Members & methods Attributes & routines Queries & commands Similar to what appears in the box in a UML class diagram

ANU COMP2110 Software Design in 2003 Lecture 10Slide 4 Routine interfaces The information a client (caller) needs What the routine does, not how it does it Name (well-chosen) Return type Argument types Roles of arguments One line description Contract? Best generated by tools e.g. short, Javadoc } Signature

ANU COMP2110 Software Design in 2003 Lecture 10Slide 5 2. Contracts See Meyer Object-Oriented Software Construction Chapter 11 (p.331ff) Ideas come from formal verification – can lead to formal correctness proofs Doesn't have to go that far

ANU COMP2110 Software Design in 2003 Lecture 10Slide 6 Pre- and Post-conditions Precondition: What the routine assumes to be true before it starts Postcondition: What the routine guarantees to be true when it returns Contract: { pre } body { post } “If you promise to call me with my preconditions satisfied, then I promise to deliver you a final state in which my postconditions are satisfied.”

ANU COMP2110 Software Design in 2003 Lecture 10Slide 7 Contract violations – whose fault? Precondition violation = bug in client (caller) Postcondition violation = bug in supplier It's as simple as that!

ANU COMP2110 Software Design in 2003 Lecture 10Slide 8 How strong should preconditions be? Too many / too strong “Customer is always wrong” Routine can't be used Too few / too weak “Customer is always right” Writing the routine becomes impossible Guidelines for writing preconditions: Must appear in documentation for client code Must be justifiable from the requirements

ANU COMP2110 Software Design in 2003 Lecture 10Slide 9 Class invariants Global properties of the class Must be satisfied by every instance at all times (except briefly during operations) e.g for a stack: empty = (count = 0) count >= 0 Creation routine must establish invariant Contract is now: { pre and inv } body { post and inv } (There are also loop invariants and variants: see notes for COMP1110 and COMP2100)

ANU COMP2110 Software Design in 2003 Lecture 10Slide 10 Contracts as documentation Add to the less formal description given as part of the interface Major benefit is to remove duplication: Supplier does not have to check that the precondition has been satisfied. (That's the client's job.) Client does not have to check that the postcondition has been satisfied. (That's the supplier's job.)

ANU COMP2110 Software Design in 2003 Lecture 10Slide Pseudocode Halfway between natural language and computer code Use indenting and informal control structures Do not use technical language Do not use details from implementation language. (In other words, the same pseudocode should work for Eiffel or Java or C++ or Smalltalk C or Pascal or Fortran or Ada Bash or Perl or Python or Csh

ANU COMP2110 Software Design in 2003 Lecture 10Slide 12 How to write pseudocode Break down the body of the routine into steps Write at the level of intent Still “What” not “How” but at a lower level of abstraction Must be at a higher level of abstraction than the finished code Big idea: The pseudocode becomes the comments in the finished code.

ANU COMP2110 Software Design in 2003 Lecture 10Slide 13 Example: Merge sort if the list has more than one element then divide the list into two equal parts merge sort the first part merge sort the second part while both halves are non-empty do compare their first elements and select the smaller end while copy the remaining elements end if

ANU COMP2110 Software Design in 2003 Lecture 10Slide 14 Good and bad pseudocode (From Steve McConnell: Code Complete) Increment resource number by 1 allocate a dlg struct using malloc if malloc returns NULL then return 1 invoke Osrsrc_init to initialise a resource for the operating system set *hRsrcPtr equal to resource number return 0 Keep track of number of resources in use If another resource is available then Allocate a resource structure If a dialog box structure could be allocated then Note that one more resource is in use Initialise the resource Store the resource number end if return True if a new resource was created, otherwise return False

ANU COMP2110 Software Design in 2003 Lecture 10Slide 15 More on good pseudocode (and comments) Think of comments (lines of pseudocode) as paragraph headings in the finished code Focus on what and why, not how Don't just repeat what the code does Always write at the level of intent, not at the level of implementation Write at a sufficiently low level that writing the code itself will be almost automatic for a skilled programmer with no knowledge of the system or its design (a code monkey)