Slides with material from Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 3: HW4, ADTs, and more.

Slides:



Advertisements
Similar presentations
Classes and Objects CMSC 202. Version 9/122 Programming & Abstraction All programming languages provide some form of abstraction. – Also called information.
Advertisements

MIDTERM REVIEW. Abstraction Functions Internal (like the representation invariant) Client doesn’t need this! Can be used to show code correctness when.
try { Assert(Life. Real); Assert(Life
Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 5: HW6 and Interfaces.
Abstraction Functions. Announcements Exam 1 on Tuesday March 3 rd Closed book/phone/laptop 2 cheat pages allowed (handwritten or typed) 1 double-sided.
Interfaces. In this class, we will cover: What an interface is Why you would use an interface Creating an interface Using an interface Cloning an object.
1 Doc Comment Conventions. 2 Write for your audience Rule 32: Write documentation for– those who must use your code Users should not need to care how.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Perimeter Rectangles, Squares, and Triangles Perimeter Measures the distance around the edge of any flat object. To find the perimeter of any figure,
Abstract data types What does ‘ abstract ’ mean? From Latin: to ‘ pull out ’— the essentials –To defer or hide the details –Abstraction emphasizes essentials.
CSE 331 Software Design & Implementation Dan Grossman Fall 2014 Data Abstraction: Abstract Data Types (ADTs) (Based on slides by Mike Ernst, David Notkin,
Slides by Vinod Rathnam with material from Alex Mariakakis Kellen Donohue, David Mailhot, and Hal Perkins Midterm Review.
Computer Science 340 Software Design & Testing Design By Contract.
Ranga Rodrigo. Class is central to object oriented programming.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
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.
Perimeter & Circumference Return to table of contents.
Polymorphism, Abstraction and Virtual Functions. In this slide, we introduce virtual functions and two complex and powerful uses for derived classes that.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
A programmer’s wife tells him, “Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen.” The programmer.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Abstract Data Types – Examples / Summary (Based on slides by Mike Ernst and David Notkin)
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
BTS430 Systems Analysis and Design using UML Domain Model—Part 2A: Attributes.
Domain Model A representation of real-world conceptual classes in a problem domain. The core of object-oriented analysis They are NOT software objects.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
CSE 331 Software Design & Implementation Dan Grossman Fall 2014 Abstraction Functions (Based on slides by Mike Ernst, David Notkin, Hal Perkins)
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
SLIDES ADAPTED FROM ALEX MARIAKAKIS, WITH MATERIAL FROM KRYSTA YOUSOUFIAN, MIKE ERNST, KELLEN DONOHUE Section 5: HW6 and Interfaces Justin Bare and Deric.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
CSE 1030: Implementing Static Features Mark Shtern.
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
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 Hal Perkins Winter 2015 Data Abstraction: Abstract Data Types (ADTs) (Based on slides by Mike Ernst, Dan Grossman,
Important Annoucement 1  I messed up something in the last class  if a subclass overrides a method that throws an exception then it must either 1. throw.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Representation Invariants and Abstraction Functions.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
A programmer’s roommate tells him, “Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen.” The programmer.
Slides by Alex Mariakakis Section 5: Midterm Review.
Abstract Data Type.
1Z0-808 Exam : Java SE 8 Programmer I
Section 8: Model-View-Controller
MTH108 Business Math I Lecture 2.
CSE 331 Software Design & Implementation
Section 8: Model-View-Controller
Introduction to Graphing
Section 5: HW6 and Interfaces
Design by Contract Fall 2016 Version.
Section 5: HW6 and Interfaces
Introduction to Data Structures
Section 6: Midterm Review
Slides by Steve Armstrong LeTourneau University Longview, TX
Equality, conclusion Based on material by Michael Ernst, University of Washington.
Data Structures and Algorithms for Information Processing
The programmer returns with 12 loaves of bread.
Section 3 Graphs & Testing
Section 4: Interfaces Parsing Data and
Section 5: HW6 and Interfaces
Section 4: Graphs and Testing
IMPORTANT NOTE Some parts of these section slides deal with null ints. This was a mistake, as primitives cannot be null. These issues have been corrected.
Warmup ["hip","hip"] = Hip Hip Array! ???.
Section 5: HW6 and Interfaces
CSE 331 Software Design & Implementation
Computer Science 340 Software Design & Testing
Presentation transcript:

Slides with material from Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 3: HW4, ADTs, and more

Agenda HW4: fun with math review! Abstract data types (ADTs) Method specifications

Polynomial Addition 3x 5 + 5x 4 - 2x 3 - x 2 + x + 0 3x 5 - 2x 3 + x – 5 + (5x 4 + 4x 3 - x 2 + 5)(3x 5 - 2x 3 + x – 5) + 5x 4 + 4x 3 - x x + 0x 2 + 0x 4

Polynomial Multiplication + 4x 4 -21x 3 + 5x 2 + 5x x 3 + 5x 2 – 25 4x 3 - x x – 5 * (4x 3 - x 2 + 5)(x – 5) * 4x 4 -x 3 + 5x

Polynomial Division 5x 6 + 4x 4 – x x 3 - 2x – 5 (5x 6 + 4x 4 – x 3 + 5)(x 3 - 2x – 5) /

Polynomial Division x x x x x 3 - 2x – 5

ADT Example: Line Suppose we want to make a Line class that represents lines on the Cartesian plane. See /conceptual-info/specifications.html/conceptual-info/specifications.html for more.

Definitions Abstract Value: what an instance of a class is supposed to represent Line represents a given line Abstract State: the information that defines the abstract value Each line has a start point and an end point Abstract Invariant: the conditions (if needed!) that must remain true over the abstract state for all instances Start point and end point must be distinct

Definitions (cont.) Specification Fields: describes components of the abstract state of a class Line has specification fields startPoint, endPoint Derived Specification Fields: information that can be derived from specification fields but useful to have length = sqrt((x1-x2)^2 + (y1-y2)^2)

ADT Example: Line /** * This class represents the mathematical concept of a line segment. * * Specification fields: start-point : point // The starting point of the line. end-point : point // The ending point of the line. * * Derived specification fields: length : real // The length of the line. * * Abstract Invariant: * A line's start-point must be different from its end-point. */ public class Line { … }

ADT Example: Line /** * This class represents the mathematical concept of a line segment. * * Specification fields: start-point : point // The starting point of the line. end-point : point // The ending point of the line. * * Derived specification fields: length : real // The length of the line. * * Abstract Invariant: * A line's start-point must be different from its end-point. */ public class Line { … } Abstract Value

ADT Example: Line /** * This class represents the mathematical concept of a line segment. * * Specification fields: start-point : point // The starting point of the line. end-point : point // The ending point of the line. * * Derived specification fields: length : real // The length of the line. * * Abstract Invariant: * A line's start-point must be different from its end-point. */ public class Line { … } Abstract State

ADT Example: Line /** * This class represents the mathematical concept of a line segment. * * Specification fields: start-point : point // The starting point of the line. end-point : point // The ending point of the line. * * Derived specification fields: length : real // The length of the line. * * Abstract Invariant: * A line's start-point must be different from its end-point. */ public class Line { … } Abstract Invariant

ADT Example: Line /** * This class represents the mathematical concept of a line segment. * * Specification fields: start-point : point // The starting point of the line. end-point : point // The ending point of the line. * * Derived specification fields: length : real // The length of the line. * * Abstract Invariant: * A line's start-point must be different from its end-point. */ public class Line { … } Specification Fields

ADT Example: Line /** * This class represents the mathematical concept of a line segment. * * Specification fields: start-point : point // The starting point of the line. end-point : point // The ending point of the line. * * Derived specification fields: length : real // The length of the line. * * Abstract Invariant: * A line's start-point must be different from its end-point. */ public class Line { … } Derived Fields

ADT Example: Circle Suppose we want to make a Circle class that represents circles on the Cartesian plane.

ADT Example: Circle Abstract Value: Circle represents a given circle Abstract State: Abstract Invariant Option #1: r > 0, center must exist Option #2: center and edge must be distinct Option #3: corner1 and corner2 must be distinct

ADT Example: Circle Specification Fields: Option #1: r and center Option #2: center and edgePoint Option #3: corner1 and corner2 Derived Specification Fields: Circumference Diameter Area …

Specification Fields vs. Derived Specfields Rectangle: corner1, corner2, length1, length2, area Specification fields: corner1 corner2 Derived: Length, area ShoppingCart: itemlist, total Item: name, quantity, price, total Specification and derived specification?

Abstraction Abstract values, state, and invariants specify the behavior of classes and methods What should my class do? We have not implemented any of these ADTs yet Implementation should not affect abstract state As long as Circle represents the circle we are interested in, nobody cares how it is implemented

Abstract vs. Concrete We’ll talk later about representation invariants, which specify how the abstract invariant is implemented Boolean: is this a valid instance of our object What does it mean for something to be well-formed? Eg: Date with a negative day We’ll also discuss how abstraction functions map the concrete representation of an ADT to the abstract value Only defined for things that are well-formed What should the concrete object do, in the abstract view? Eg: what does Date.next do?

Javadoc Documentation Tool made by Oracle for API documentation We’ve already seen Javadoc for external class specification Method specifications will describe method behavior in terms of preconditions and postconditions

Javadoc Method : the statements that must be met by the method’s : the value returned by the method, if : the exceptions that may be raised, and under which : the variables that may change because of the : the side effects of the method

Javadoc Method Tags is not met, anything can happen False implies everything The conditions must be a subset of the precondition Ex: If a x > should not say anything about x < lists what may change, indicates how they change If a specification field is listed in clause but not in clause, it may take on any value (provided that it follows the abstract invariant) If you mention a field you should try to specify what happens

JAVADOC DEMO!

Polynomial practice! (x 2 + 3x + 5) - (4x 3 – 2x 2 + 3x - 2) -4x 3 + 3x (x 3 – 3x + 1) * (x - 3) x 4 - 3x 3 – 3x x -3 (3x 3 – 2x 2 + 4x -3) / (x 2 + 3x + 3) (3x – 11), remainder (28x + 30)