CS201J: Engineering Software, Fall 2002
|
Notes: Tuesday 15 October 2002
Schedule Substitution Principle
- Now: Exam 1
- Thursday, October 24: Problem Set 5: Part 1
- Thursday, October 31: Problem Set 5: Part 2
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
- 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.
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
University of Virginia
Department of Computer Science
CS 201J: Engineering Software
Sponsored by the
National Science Foundationcs201j-staff@cs.virginia.edu