cs205 Friday 22 September 2006
Upcoming Schedule
Midterm Exam
The midterm exam will be handed out next Friday, 29 September, and due
Monday, 2 October. It will cover material through class 15 (Monday, 25
September) including problem sets 1-3, chapters 1-5, 7, 9, and 10, and
lectures 1-15. The exam is take home and open book, but you will not be
permitted to use other humans or a Java compiler for the exam (unless
you write your own).
You should not be surprised if the exam contains questions about
specifying procedures, data abstraction, specifying data abstractions,
implementing data abstractions (including choosing good representations,
rep invariants and abstraction functions), testing, and subtyping.
The recommended ways to study for the exam are:
- Go over the sample exam posted last week (
http://www.cs.virginia.edu/evans/cs205/exams/sample1/exam.html).
After you have tried the questions on your own, read the comments (http://www.cs.virginia.edu/cs205/exams/sample1/comments.html).
- Go over the problem sets and make sure you understand the comments.
- Look over the notes and check that you can answer the questions on the notes.
- Re-read sections from the book
Substitution Principle
Parameters | Psub ≥ Psuper |
Preconditions | pre_super implies pre_sub |
| |
Result | Rsub ≤ Rsuper |
Postconditions | post_sub implies post_super |
| |
Properties | properties_sub implies properties_super |
If A implies B, which is stronger?
Remember the logical table for implies (A => B):
Subtyping Example
MysteryType1 mt1;
MysteryType2 mt2;
MysteryType3 mt3;
... (anything could be here)
mt1 = mt2.m (mt3);
If the Java compiler is happy with this code, which of these are
guaranteed to be true:
- The apparent type of mt2 is MysteryType2
- At the last statement, the actual type of mt2 is MysteryType2
- MysteryType2 has a method named m
- The MysteryType2.m method takes a parameter of type MysteryType3
- The MysteryType2.m method returns a subtype of MysteryType1
- After the last statement, the actual type of mt1 is MysteryType1
Strangely enough, some workers in the field have been advocating a
contravariant policy. Here it would mean that if we go for example to
class RANKED_GIRL, where the result of roommate is naturally redefined
to be of type RANKED_GIRL, we may for the argument of routine share use
type GIRL, or rather scaringly, SKIER of the most general kind. One
type that is never permitted in this case is RANKED_GIRL! Here is what,
under various mathematical excuses, some professors have been
promoting. No wonder teenage pregnancies are on the rise.
Bertrand Meyer's justification for violating the substitution principle
from
Static Typing and
Other Mysteries of Life