Representation Invariants CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Giving a formal meaning to “Specialization” In these note we try to give a formal meaning to specifications, implementations, their comparisons. We define.
Computer Science and Engineering College of Engineering The Ohio State University Classes and Objects: Members, Visibility The credit for these slides.
Announcements We are done with homeworks Second coding exam this week, in recitation –Times will be posted later today –If in doubt, show up for your regular.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Design by Contract. Specifications Correctness formula (Hoare triple) {P} A {Q} – A is some operation (for example, a routine body) – P and Q are predicates.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
Introduction to Software Engineering Lecture 7 André van der Hoek.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Outline Java program structure Basic program elements
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Analysis Modeling (cont’d) CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides.
Ranga Rodrigo. Class is central to object oriented programming.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Analysis Modeling (cont’d) CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides.
Class Specifications CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides are intended.
Implementing Specifications CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
Classes CS 21a: Introduction to Computing I First Semester,
CSE 222: Software Components in Engineering (SCE) – Introduction Instructor: Jimmy Voss Disclaimer: Not all material is original. Some is taken from the.
Programming Languages and Paradigms Imperative Programming.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface.
Analysis Modeling (cont’d) CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides.
CCSS.ELA-LITERACY.RL CCSS.ELA-LITERACY.RL DETERMINE TWO OR MORE THEMES OR CENTRAL IDEAS OF A TEXT AND ANALYZE THEIR DEVELOPMENT OVER THE.
Introduction to Design (and Zen) CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These.
Analysis Modeling CpSc 372: Introduction to Software Engineering
(c) University of Washington16-1 CSC 143 Java Lists via Links Reading: Ch. 23.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 9: Continuing with classes.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
1104B – Dr. Jackie.  Papers were great!  Everyone hit the mark  Remember to contact me ◦ ◦ On AIM at
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
CS-2852 Data Structures LECTURE 2 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
The Software Process CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides are intended.
Independent Research Strategies for the Exit Project Enrich Social Studies Exit Project with Technology iLearn Social Studies Session 4 of 8.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
Kakihijau.googlepages.com Introduction To Greenfoot Part-3.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Interfaces CMSC 202. Public Interfaces Objects define their interaction with the outside world through the their public interface. A class' public interface.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
1 CS162: Introduction to Computer Science II Abstract Data Types.
1 i206: Lecture 17: Exam 2 Prep ; Intro to Regular Expressions Marti Hearst Spring 2012.
The need for Programming Languages
Working with Java.
Introduction to C++ Programming Language
Chapter 5 Ordered List.
Efficiency of in Binary Trees
Lists Chapter 4.
Data Structures Lakshmish Ramaswamy.
COP 3503 FALL 2012 Shayan Javed Lecture 8
Introduction to javadoc
Chapter 5 Ordered List.
Component-Level Design
Introduction to Java Programming
Chapter 1: Computer Systems
ArrayLists 22-Feb-19.
Introduction to javadoc
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Classes CS 21a: Introduction to Computing I
How to Avoid Plagiarism
Professors Dr. Lisa Forrester English Jacqueline Hernandez MEd. INRW
Presentation transcript:

Representation Invariants CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These slides are intended to serve as teaching instruments for an undergraduate course in Software Engineering. While the slides were formatted by Dr. Hallstrom, the content is compiled from other sources, including the readings listed on the course website, Dr. Pressman’s Software Engineering textbook, and various internet materials. In almost every case, the ideas belong to someone other than Dr. Hallstrom. Indeed, text is often quoted verbatim without an explicit citation (to improve the readability of the slides). The original authors retain all copyrights. If you are interested in citing any of the material in these slides, please contact Dr. Hallstrom for the original source(s). DO NOT CITE THIS PRESENTATION. THE CONTENT SHOULD NOT BE ATTRIBUTED TO DR. HALLSTROM. SEE DR. HALLSTROM IF YOU HAVE ANY QUESTIONS.

CpSc 372 Implementation Rules When implementing an interface, we sometimes impose rules to allow our method implementations to work together. modeled by: String of Object modeled by: Set of Object represents Consider implementing the Set interface using an implementation of Sequence.

CpSc 372 Interface Review Recall the interface specifications that we’ve discussed. public interface Set { void clear(); void add(Object x); void remove(Object x); Object removeAny(); boolean isIn(Object x); int getSize(); } public interface Sequence { void clear(); void add(int pos, Object x); Object remove(int pos); Object getElement(int pos); int getLength(); } modeled by: String of Object modeled by: Set of Object

CpSc 372 Correct Implementation? public class SetImpl1 implements Set { /* representation: self = elements(self.items) */ private Sequence items; public SetImpl1() { items = new SequenceImpl1(); } … public void remove(Object x) { for(int i = 0; i < items.getLength(); i++) { if(items.getElement(i).equals(x)) { items.remove(i); return; } … }

CpSc 372 Correct Implementation? public class SetImpl1 implements Set { /* representation: self = elements(self.items) */ private Sequence items; public SetImpl1() { items = new SequenceImpl1(); } … public void add(Object x) { items.add(x); } … } Considered in isolation, is the body of add() correct?

CpSc 372 What is a Representation Invariant? A representation invariant is expressed as a property that must be satisfied at the start and end of every method invocation.  Expressed over concrete state space  Satisfied at object creation  Satisfied at method termination A representation invariant characterizes a set of rules that must be respected by every method implementation.

CpSc 372 The Convention Clause public class SetImpl1 implements Set { /* representation: self = elements(self.items) convention: */ private Sequence items; public SetImpl1() { items = new SequenceImpl1(); } … }

CpSc 372 Another Example What if we wanted to use binary search within the body of isIn() ? public class SetImpl1 implements Set { /* representation: self = elements(self.items) convention: */ … }