CS201J: Engineering Software, Fall 2003
|
Notes: Thursday 16 October 2003
Schedule There will be no sections tomorrow. Work on Exam 1.
- Tuesday, 21 October (12:30pm) Exam 1
Substitution Principle
B is a subtype of A means wherever an object of type A isexpected, we can use an object of type B instead.Subtyping ExampleFor a function f (A), if f satisfies its specification when passed an object whose actual type is type A, f also satisfies its specification when passed an object whose actual type is B.
Signature Rule
Java's rule is stricter (novariant) — subtype signatures must match supertype signatures (except the subtype may throw fewer exceptions).
- Subtype must implement all of the supertype methods
- Argument types must not be more restrictive (contravariant)
- Result type must be at least as restrictive (covariant)
- Subtype method must not throw exceptions that are not subtypes of exceptions thrown by supertype
Methods Rule
Properties Rule
- Precondition of the subtype method must be weaker than the precondition of the supertype method: mA.pre implies mmB.pre
- Postcondition of the subtype method must be stronger than the postcondition of the supertype method: mB.post implies mA.post.
- Subtype must preserve all properties in the supertype's overview specification.
class A { public RA m (PA p) ; } class B extends A { public RB m (PB a); }Substitution Principle Parameters PB >= PA Preconditions pre_A implies pre_B Result RB <= RA Postconditions post_B implies post_A
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
Java and C++ make you think that the new ideas are like the old ones.
Java is the most distressing thing to hit computing since MS-DOS.
Alan KayDon't worry about what anybody else is going to do. The best way to predict the future is to invent it.
Really smart people with reasonable funding can do just about anything that doesn't violate too many of Newton's Laws!
Alan KayAnd they showed me really three things. But I was so blinded by the first one I didn't even really see the other two. One of the things they showed me was object oriented programming they showed me that but I didn't even see that. The other one they showed me was a networked computer system...they had over a hundred Alto computers all networked using email etc., etc., I didn't even see that. I was so blinded by the first thing they showed me which was the graphical user interface. I thought it was the best thing I'd ever seen in my life. Now remember it was very flawed, what we saw was incomplete, they'd done a bunch of things wrong. But we didn't know that at the time but still though they had the germ of the idea was there and they'd done it very well and within you know ten minutes it was obvious to me that all computers would work like this some day.
Steve Jobs (on seeing a Smalltalk demo on his 1979 visit to Xerox PARC)
University of Virginia Department of Computer Science CS 201J: Engineering Software |
Sponsored by the National Science Foundation |
cs201j-staff@cs.virginia.edu |