Chapter 11

Substitutability

There is no substitute for hard work.

—Thomas Alva Edison:Life (1932)

One’s style is one’s signature always.

—Oscar Wilde:Letter to the Daily Telegraph (1891)

This rather lengthy chapter is concerned with a series of interconnected prescriptions, all of them having to do with the notion of substitutability and its numerous ramifications.

IM PRESCRIPTION 16: VALUE SUBSTITUTABILITY

Let Op be a read-only operator, let P be a parameter to Op, and let T be the declared type of P. Then the declared type of the argument expression (and therefore, necessarily, the most specific type of the argument as such) corresponding to P in an invocation of Op shall be allowed to be any subtype T′ of T. In other words, the read-only operator Op applies to values of type T and therefore, necessarily, to values of type T′The Principle of Read-Only Operator Inheritance. It follows that such operators are polymorphic, since they apply to values of several different types—The Principle of Read-Only Operator Polymorphism. It further follows that wherever a value of type T is permitted, a value of any subtype of T shall also be permitted—The Principle of Value Substitutability.

image

The main purpose of IM Prescription 16 is (a) to pin down precisely the notion of value substitutability—which by now should be very familiar to you—and (b) more specifically, to define three interrelated ...

Get Type Inheritance and Relational Theory now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.