CS201J: Engineering Software, Fall 2003
|
Notes: Tuesday 21 October 2003
Schedule
- Tuesday, 21 October (12:31pm): Exam 1
- Thursday, 30 October: PS5 Part 1
- Tuesday, 11 November: PS5 Part 2
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.
For 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 — Subtype must preserve all properties in the supertype's overview specification.
- 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.
class A { public RA m (PA p) ; } class B extends A { public RB m (PB a); } Substitution Principle Eiffel Parameters PB >= PA PB <= PA Preconditions pre_A implies pre_B pre_B implies pre_A Result RB <= RA RB <= RA Postconditions post_B implies post_A post_B implies post_AMust 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
University of Virginia Department of Computer Science CS 201J: Engineering Software |
Sponsored by the National Science Foundation |
cs201j-staff@cs.virginia.edu |