Specifications Liskov Chapter 9 SWE 619 Last Updated Fall 2008.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

EECE 310: Software Engineering Modular Decomposition, Abstraction and Specifications.
The Substitution Principle SWE 332 – Fall Liskov Substitution Principle In any client code, if subtype object is substituted for supertype object,
Data Abstraction II SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Software Engineering and Design Principles Chapter 1.
Software Testing and Quality Assurance
UI Standards & Tools Khushroo Shaikh.
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.
From Module Breakdown to Interface Specifications Completing the architectural design of Map Schematizer.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
CSC 395 – Software Engineering Lecture 21: Overview of the Term & What Goes in a Data Dictionary.
Describing Syntax and Semantics
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstraction Classification, generalization, and aggregation are the basic ways we have of structuring.
Chapter 3 Object-Oriented Analysis of Library Management System(LMS)
Cs205: engineering software university of virginia fall 2006 Semantics and Specifying Procedures David Evans
Procedure specifications CSE 331. Outline Satisfying a specification; substitutability Stronger and weaker specifications - Comparing by hand - Comparing.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
Cs205: engineering software university of virginia fall 2006 Data Abstraction David Evans
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
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.
Recall The Team Skills 1. Analyzing the Problem (with 5 steps) 2. Understanding User and Stakeholder Needs 3. Defining the System 4. Managing Scope 5.
Lecture 3 Uses Cases Topics UML Use Cases pop quiz Readings: Chapter 3 January 24, 2008 CSCE 492 Software Engineering.
Two Parts of Every ADT An abstract data type (ADT)  is a type for encapsulating related data  is abstract in the sense that it hides distracting implementation.
CS551 - Lecture 8 1 CS551 Modelling with Objects (Chap. 3 of UML) Yugi Lee STB #555 (816)
A Use Case Primer 1. The Benefits of Use Cases  Compared to traditional methods, use cases are easy to write and to read.  Use cases force the developers.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Reasoning about programs March CSE 403, Winter 2011, Brun.
© Paul Ammann, 2008 Design by Contract Paul Ammann CS/SWE 332.
Semantics In Text: Chapter 3.
Ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
Type Abstraction Liskov, Chapter 7. 2 Liskov Substitution Principle In any client code, if the supertype object is substituted by a subtype object, the.
Type Abstraction SWE Spring October 05Kaushik, Ammann Substitution Principle “In any client code, if supertype object is substituted.
Software Engineering 2 -Prakash Shrestha.
Polymorphism Liskov 8. Outline equals() Revisiting Liskov’s mutable vs. not rule Polymorphism Uniform methods for different types “easy” polymorphism.
Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract,
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Data Abstraction SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
Understanding ADTs CSE 331 University of Washington.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Polymorphism SWE 619. Outline equals() Revisiting Liskov’s mutable vs. not rule Polymorphism Uniform methods for different types “easy” polymorphism Element.
Iteration Abstraction SWE Software Construction Fall 2009.
Loop Invariants and Binary Search Chapter 4.4, 5.1.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Requirement Specification SRS document is a contract between the development team and the customer How do we communicate the Requirements to others? Firm.
Modular Decomposition, Abstraction and Specifications
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Algorithms and Problem Solving
Input Space Partition Testing CS 4501 / 6501 Software Testing
GC211Data Structure Lecture2 Sara Alhajjam.
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Specifications Liskov Chapter 9
Type Abstraction SWE Spring 2009.
Programming Languages 2nd edition Tucker and Noonan
Type Abstraction Liskov, Chapter 7.
Iteration Abstraction
SWE 619 Software Construction Last Modified, Fall 2015 Paul Ammann
619 Final Review Last updated Spring 2010 © : Paul Ammann.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Type Abstraction SWE Spring 2013.
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Specifications Liskov Chapter 9 SWE 619 Last Updated Fall 2008

2 Overview/Agenda Review why we use specifications as a software construction tool? Restating the reasons from chapter 1 How to write good specs (for desired behavior)? Advice from Liskov Some formal ways to specify behavior Z, OCL (SWE 623)

3 Why Specifications? What do specifications do? Who is the target audience? How are they constructed? What is their use? Do they evolve?

4 Construction Intended for: designers, implementers, testers, maintenance people, clients In short: intended for people [users] How formal can specifications be? Must clearly state what the must the software do Can informal specs be clear? Must be understood by users of the specification.

5 Use Implementers: understand system requirements, tasks to be performed Testers: Understand functional requirements Clients: understand how to use the software

6 Understanding abstractions What must be understood? Behavior of some abstraction How to specify behavior? abstract state, changes to abstract state abstract descriptions Leads to multiple implementations that satisfy an abstraction Satisfy? Implementations follow contract i.e., pre and post conditions

7 Meaning of an abstraction The set of implementations that satisfy an abstraction is the specificand set. Specificand set is the meaning of an abstraction Example public int 3DigitNumber() //E: return an integer greater than 99 // and less than 1000 What is the meaning of this abstraction?

8 Liskov example static int p (int y) // R: y > 0 // E: returns x such that x > y Specificand set: (possible implementations) {return y + 1;}, { return y + k ;} (k > 0) {return y * 2;}, {return y * k ; } (k > 1) {return 4y – 2;} What about {return 4y – 3;} ?

9 Liskov example (contd.) static int p (int y) // R: true // E: returns x such that x > y What does strengthening/weakening of pre/post conditions do to the specificand set? weakening pre  smaller specificand set New set is a subset of old set strengthening post  smaller specificand set Again, new set is a subset of old set

10 Specs for desired behavior Note that “desired” differs from “correct” Specs determine specificand set Do all members of specificand set exhibit desired behavior? Throw out implementations that do not Are there missing members of specificant set? Add implementations that are missing

11 Sufficiently restrictive specs Rephrase specs  prune specificand set Example: Iterator for a (mutable) bag bag = [Book, Book, Pen, Pencil] //E: returns every element in bag Type of implementations for this spec? Duplicates? Elements not in bag? What about order? What about mutability?

12 Refining specs for desired behavior If do not desire duplicates (i.e. Pen once, Book once): // E: returns all unique elements in bag only once If order matters: // E: returns elements in order they were put in the bag (FIFO) If mutability matters: // R: No change to bag while iterator in use // E: returns every element in bag

13 Refining specs for desired behavior (contd.) If mutability matters: //E: returns every element in bag, throws // CME if iterator modified while in use If only elements in bag desired: //E: returns only the elements in bag

14 Sufficiently general specs Apparent contradiction with the earlier goal of pruning specs! What if the specs are over specified? i.e., some valid and desired implementations are not the members of the specificand set Over specifications are bad in the sense that some desired implementations are lost

15 Classic over specification e.g. Consider a container with method: public Object getElement() Desire any one element from the container Spec: //E: returns 3 rd element in the container Obviously over-constrained.

16 Generality of specs Specifications come in 2 flavors Operational: A recipe or algorithm Definitional: Some property or constraints that inputs/outputs satisfy Prefer definitional specs More freedom to implementer regarding choice of algorithm But not a natural choice for most students

17 Clarity Every user of the spec should have the same interpretation of the spec! Possible if we allow formal specs Not easy to understand formal specs! Clear, unambiguous specifications are hard to get Expect to make mistakes! What to do? Allow redundancy in specs

18 Redundancy Specs are not concise  Easier to understand 2 flavors i.e.redundant definition e.g.provide an example Reduces chances of missing an important point

19 Liskov example static boolean subset (Set s1, Set s2) throws NPE // E: if s1 or s2 is null, throws NPE else returns true // if s1 is a subset of s2, else returns false Makes sense to every reader What could be wrong here?

20 Example contd. What if s1 equals s2? Design decision about what to return for improper subset. Rephrasing specs as: //E: … NPE else, returns true if every element of s1 is an element of s2, else false Is this a better spec?

21 Example continued Second spec allows improper subset Eliminates ambiguity. But why not use accepted terms? Liskov: don’t replace, include both! //E: …NPE, returns true if s1 is a subset of s2, i.e., returns true if every element of s1 is an element of s2, else false

22 Alternate spec Still better way to make sense to a wide variety of audience is to add more redundancy (without being repetitive) // E: … NPE, returns true if s1 is a subset of s2, i.e., returns true if every element of s1 is an element of s2, else false, e.g., subset({7}, {3, 7}) returns true, subset({3}, {7}) returns false, subset ({7}, {7}) returns true

23 How much effort into specs? Avoid verbosity, repetitiveness but not compromise on clarity Examples are powerful as specifiers, good idea to include them Only a handful of examples can help you think about restrictive and general specs

24 Test Driven Development as a Specification Exercise Basic idea: Define tests first Then develop code to satisfy tests Lots of process stuff as well Connection to current lecture: Specification examples are tests Specification examples greatly help specifier understand abstraction Rule of thumb: Most development artifacts are more useful if they are executable

25 Formal specifications Specifications/ Analysis in Z (Zed) Occasionally taught in SWE 623 Basis for OCL in UML

26 Specification in Z Scenario: We maintain a membership list and an associated phone database. [Person, Phone] |----PhoneDB |members: P Person (‘set of’ person) |phones : Person  Phone (relation) | |dom phones ⊆ members (invariant) |

27 Z Operation: Assign a Phone Scenario: Someone would like a phone. (Note: Missing precondition) |----Assign | p? : Person; n? : Phone |  PhoneDB | | phone’ = phone  { p?  n? } | members’ = members |

28 Example members  {jim, sue} phones {(jim, 1231), (sue, 3956)} Assign(alice, 1231) Cool Z property: Can calculate minimal preconditions!! Simple analysis: leave out preconditions and find minimum constraint to maintain invariants!