


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Engineering Software; Subject: Computer Science; University: University of Virginia; Term: Fall 2006;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



cs205: engineering software university of virginia fall 2006
www.cs.virginia.edu/cs
cs205: engineering software 2
cs205: engineering software 3
cs205: engineering software 4
class A { public RA m (PA p) ; } class B extends A { public RB m (PB p) ; } RB must be a subtype of RA: RB <= RA PB must be a supertype of PA: PB >= PA covariant for results, contravariant for parameters
cs205: engineering software 5
mA.pre ⇒ mB.pre
cs205: engineering software 6
public int f (a A, x X) { // REQUIRES: a is initialized // EFFECTS: returns a.value * x.value return a.m (x); public class A { } // An A may be initialized or uninitialized. // An initialized A has an associated int value. public int m (x X) { // REQUIRES: this is initialized } (^) public class B extends A { // A B may be initialized or uninitialized. // A B may be awake or asleep. // An initialized B has an associated int value. public int m (x X) { // REQUIRES: this is initialized and awake } Can’t make the precondition stronger! The callsite might not satisfy it.
cs205: engineering software 7
public int f (a A, x X) { // REQUIRES: a is initialized // EFFECTS: returns a.value * x.value return a.m (x); } public class A { // An A may be initialized or uninitialized. // An initialized A has an associated int value. public int m (x X) { // REQUIRES: this is initialized } public class B extends A { // A B may be initialized or uninitialized. // A B may be awake or asleep. // An initialized B has an associated int value. public int m (x X) { // REQUIRES: nothing } Okay, precondition is weaker cs205: engineering software 8
cs205: engineering software 9
cs205: engineering software 10
cs205: engineering software 11
cs205: engineering software 12
… (in client code) MysteryType1 mt1; MysteryType2 mt2; MysteryType3 mt3; … (anything could be here) mt1 = mt2.m (mt3); If the Java compiler accepts this code, which of these are guaranteed to be true: a. The apparent type of mt2 is MysteryType b. At the last statement, the actual type of mt2 is MysteryType c. MysteryType2 has a method named m d. The MysteryType2.m method takes a parameter of type MysteryType e. The MysteryType2.m method returns a subtype of MysteryType f. After the last statement, the actual type of mt1 is MysteryType
cs205: engineering software 19
Skier set_roommate (Skier)
Boy (^) Girl
The types of the parameters in the subtype method may be subtypes of the supertype parameters.
How can Girl override set_roomate? set_roommate (Girl g) set_roommate (Boy b)
Opposite of substitution principle!
cs205: engineering software 20
class A { public RA m (PA p) ; } class B extends A { public RB m (PB a); }
… (in client code) MysteryType1 mt1; MysteryType2 mt2; MysteryType3 mt3; … mt1 = mt2.m (mt3); Substitution Principle Eiffel Parameters Psub ≥≥≥≥ Psuper Psub ≤≤≤≤ Psuper Preconditions pre_sub ⇒ pre_super pre_sub ⇒⇒⇒⇒ pre_super
Result Rsup ≤ Rsuper Postconditions post_sup ⇒ post_super
cs205: engineering software 21
Skier set_roommate (Skier)
Boy (^) Girl set_roomate (Girl)
cs205: engineering software 22
Must it be assumed that because we are engineers beauty is not our concern, and that while we make our constructions robust and durable we do not also strive to make them elegant?
Is it not true that the genuine conditions of strength always comply with the secret conditions of harmony? Gustav Eiffel