Abstraction Functions and Representation Invariants

Slides:



Advertisements
Similar presentations
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Advertisements

Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Mutability SWE 332 Fall 2011 Paul Ammann. SWE 3322 Data Abstraction Operation Categories Creators Create objects of a data abstraction Producers Create.
Data Abstraction II SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
CLASSES & OBJECTS Representin’ real-world things in code-space Brian Camodeca, Mercyhurst College.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Data Abstraction CS 201j: Engineering Software University of Virginia Computer Science Nathanael Paul
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Constructors and Encapsulation reading: self-checks: #10-17.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION MIDTERM REVIEW Autumn 2011.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
332 Final Review Last updated Fall 2013 Professor Ammann.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Type Abstraction SWE Spring October 05Kaushik, Ammann Substitution Principle “In any client code, if supertype object is substituted.
Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Data Abstraction SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION ABSTRACT DATA TYPES Autumn 2011.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
619 Final Review Last updated Fall 2011 Paul Ammann.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 7: A Tale of Two Graphs (and.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 6 Representation Invariants.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Constructors; Encapsulation reading: self-checks: #13-18,
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
More Sophisticated Behavior
Introduction to CS/SWE 332
Lecture 12 Inheritance.
Agenda Warmup AP Exam Review: Litvin A2
CSE 331 Software Design and Implementation
Component Implementations Using RESOLVE
CSE 331 Software Design and Implementation
CSE 331 Software Design and Implementation
CSC 480 Software Engineering
CSE373: Data Structures & Algorithms Lecture 25: Software-Design Interlude – Preserving Abstractions Catie Baker Spring 2015.
CSC 113: Computer programming II
Implementing Non-Static Features
Introduction to CS/SWE 332
Data Abstraction David Evans cs205: engineering software
SWE 619 Software Construction Last Modified, Fall 2015 Paul Ammann
CSE373: Data Structures & Algorithms Lecture 16: Software-Design Interlude – Preserving Abstractions Dan Grossman Fall 2013.
Method Verification CS/SWE 332 Paul Ammann.
Lecture 7: A Tale of Two Graphs CS201j: Engineering Software
Lecture 4: Data Abstraction CS201j: Engineering Software
619 Final Review Last updated Spring 2010 © : Paul Ammann.
619 Final Review Fall 2017 Professor Ammann.
CS 350 – Software Design Singleton – Chapter 21
CSE 331 Software Design and Implementation
Building Java Programs
Kinds of methods accessor: A method that lets clients examine object state. Examples: distance, distanceFromOrigin often has a non-void return type mutator: A.
Object-Oriented Programming: Classes, Inheritance, and Interfaces
Object-Oriented Programming: Classes, Inheritance, and Interfaces
TCSS 360, Spring 2005 Lecture Notes
Building Java Programs
Method Verification Paul Ammann.
Presentation transcript:

Abstraction Functions and Representation Invariants CS/SWE 332 Paul Ammann

Data Abstraction Abstract State (Client State) Representation State (Internal State) Methods (behavior) Constructors (create objects) Producers (return immutable object) Mutators (change state) Observers (report about state) This lecture is about state only

What is “State”? Key notion Definition: Java example: A state is an assignment of values to variables. Need to consider all possible values for each variable State space is cross product of possible values for each individual variable Java example: Variables: List list; int x; Possible States: list = [], x = 5 list = null; x = 0 list = [“cat”, “dog”]; x = -8 list = [“cat”, 1, null]; x = 0 etc.

Motivation Why hide implementation from client? Makes reimplementation (maintenance) possible! Protects implementation from client Lecture covers two key notions Abstraction function Implemented by toString() in Java Representation Invariant Not standard in Java, but fits assertion mechanisms Is available in C# (VisualStudio Code Contracts)

Abstraction Function Abstract state Representation state What the client sees Examples given in class Representation state What the implementation manipulates Abstraction function simply maps representation states to abstract states Required for any implementation Difference here – we’re documenting it! Code examples: in-class exercises

Rep Invariant Rep invariant captures constraints on implementation variables “Why my code works” English descriptions are fine But needs to be coded to be effective Can check in Junit tests Code examples: in-class exercises