Advanced Class-Based FeaturesAbadi, M. & Cardelli, L. (1996). A Theory of Objects. New York, Springer. Chapter 3: "Advanced Class-Based Features."CPSC 701.01 Object Theory |
Table of Contents | |
Separating Concepts
|
Classical OO languages unify three concepts:
|
3.2 Distinguishing Subclassing from Subtyping | |||
Separating
Subclassing
and Subtyping
|
To make object types independent of classes, we
need to decide
between:
|
||
Simple
Definition
of Subtype
|
A (oversimplified?) definition of subtype is
This doesn't take into account the co/contravariance of methods. We need to be especially careful with recursive types |
||
implies
Subtyping
|
Given simple definition above,
|
||
Subsumption
|
This replacing subclassing-is-subtyping
with subclassing-implies-subtyping:
|
3.4 Subclassing without Subtyping | ||
Subclassing is not
Subtyping
|
In section 3.2 we weakened the
relationship
between subclassing and subtyping (from subclassing-is-subtyping to subclassing-implies-subtyping) We can completely unlink the notions of subtyping and subclassing This is called subclassing-is-not-subtyping. |
|
Motivation
|
There is good reason to want to allow covariant arguments to
methods. |
|
example
|
ObjectType Max is ObjectType MinMax isConsider implementations of these types: class maxClass is class minMaxClass of maxClass is |
|
Violation
of
Contravariance
|
This is all fine, but if we were to override method max() in
some subtype
of minMaxClass, then we would violate the contravariance of method
arguments.
Therefore: Subclasses with contravariant occurrences of Self do not always induce subtypes. |
|
|
forward |
||
Rob Kremer Last Modified Aug 15, 2005 |
|