This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Sheet1 Page 1 Last Time: * Midterm Today: * Subtypes: the substitution principle * Three possible subtype refinements: * Created a subtype of IntSet: MaxIntSet * Subtyping by overriding a method * Subclassing but not subtyping * Apparent vs. Actual types * Static vs. Dynamic information * Return midterms +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Midterm recap: High: 96 Low: 8 Median: 70 Mean: 67.5 StDev: 19.8 Overall, we were pleased with the performance on the exam. Question 2a was a bit of a trick question that almost no one got right. Excluding that question, the performance on the exam was quite good. The median student can expect something in a low B or a high B-. Anyone within one standard deviation (48 or higher) is doing fine. Anyone between one and two sigma (28--47) needs to think about how to improve. Anyone below two sigma (27 or lower) needs to come speak with us about whether or not to continue in the course. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ We've talked a lot about types in class. Today, we'll add a new notion to our understanding of types: the "subtype". Suppose we have two types, S and T. We say that "S is a subtype of T", written "S <: T" if, for any instance where an object of type T is expected, an object of type S can be supplied without changing the correctness of the original computation. or If "S is a subtype of T" then objects of type T may be Sheet1 Page 2 replaced with objects of type S without altering any of the desirable properties of that program (correctness) This is called the "substitution principle". It was first described in a paper written by Barbara Liskov and Jeannette Wing. Prof. Liskov is a chaired Professor at MIT. Prof. Wing was a student of Prof. Liskov's, and is currently the Chair of the CS department at CMU. If S <: T then we also say that "T is a supertype of S". Subtypes are different from the notion of "type-convertible". For example, in any computation that expects a double, you can use an int. However, the object isn't an int when it is used---it is first converted to a double---it's physical representation changes. However, if you use a subtype where a supertype is expected, it is not converted to the supertype---instead, it is used as-is. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ In an ADT, there are three ways to create a subtype from a supertype: 1: Weaken the precondition of one or more operations. 2: Strengthen the postcondition of one or more operations. 3: Add one or more operations. The preconditions of a method are formed by its argument type signature plus it's REQUIRES clause. You weaken a REQUIRES clause by removing constraints on the caller---for example, consider the method int Foo::Bar(int baz) // REQUIRES: baz is positive and even....
View Full Document
This note was uploaded on 01/28/2010 for the course EECS 280 taught by Professor Noble during the Winter '08 term at University of Michigan.
- Winter '08