J3/98-220 Date: 01 November 1998 To: J3 From: Werner Schulz Subject: OOP in F2000: SELF and LIKE In 98-217 I introduced the special type declarations SELF and LIKE. In this paper I want to specify in more detail the purpose, semantics and rules associated with these constructs. Many OOP languages have a reserved word like self, this (in C++), current, etc. Fortran does not have reserved words, hence the seemingly circular SELF :: me syntax. 'me' can, of course, be chosen freely. It could even be SELF :: self. Why introduce a construct like SELF or LIKE? A class is the code that implements that defines the actions and variables of objects. It is necessary to be able to refer to the whole current object inside the class scope. In our everyday language we all use this concept all the time and nobody questions its immense usefulness. In the context of object-oriented programming we need the same capabilities. It is possible to implement OOP without a construct like SELF but the implementation becomes rather awkward and limited, often with severe handicaps for later extensions. The construct SELF was introduced in the first OOP language thirty years ago. The age speaks by itself for the construct. LIKE is another very useful construct but it is not so widely used in OOP languages. One reason is that certain problems of practical and theoretical nature were either unknown or overlooked. In Fortran 2000 we will have a proper definition of monomorphic and polymorphic objects (a distinction not found in all OOP languages). LIKE is added as a construct to allow programmers to express in an easy and safe manner an important class of procedures. I like to call SELF and LIKE dynamic type declarations (with respect to inheritance). This name should be become clearer after a few examples. In many practical problems one requires that at least one argument passed to the invoking object has exactly the same type. A special case are the so-called binary methods (or procedures), many of them we know better as binary operations like: a + b, a :: SELF and LIKE are dynamic declarations with respect to inheritance. They change their type each time they are inherited from the type of the parent class to the type of the new child class. SELF and LIKE are referring to monomorphic objects. SELF can only be used inside the class scope, it is a short form for the entire current object. LIKE is also only usable inside the class scope and only for declaring the type of dummy arguments. Hence the attributes are limited to those available for dummy arguments. i.e. INTENT and TARGET LIKE cannot be used to declare dummy procedures.