Restrictions on object methods


Motivation

Modula-3 allows a "class method" to be named via the following syntax: TYPE.METHODNAME This returns the actual procedure that the method is bound to. The problem is that this procedure can be called on any object that is a subtype of TYPE, even if the subtype has overridden METHODNAME for its objects. This is a safety hole, because it allows clients to break the abstraction that the subtype provides.

Implementation

We have added the following restrictions on using the TYPE.METHODNAME syntax:
  1. This syntax can only be used in the scope of the full revelation of a subtype of TYPE.
  2. When this syntax is used, the resulting procedure it can only be used in the function position of a call. It cannot be passed as argument or stored anywhere.


Other SPIN Modula-3 changes

May 20, 1996

whsieh@cs.washington.edu