2.5 methods (including multimethods and method combinations)

OODBTG Reference Model

A "method" provides the implementation of an operation forcertain objects. Different objects may have different methods for the sameoperation.

In the classical object model, a method is considered to implement theinterfaces of operation recipients, but not the interfaces of other parameters.In generalized models, a method is considered to implement the interfacesof all parameters.

OMG CORBA IDL

Code that is executed to perform a service is called a method. Whena client issues a request, a method of the target object is called. Theinput parameters passed by the requester are passed to the method and theoutput parameters and return value are passed back to the requester [CORBASpecification 2.3.1 The Execution Model: Performing Requests].

ODMG

Operations (declared in the interface) are implemented by methods definedin the type implementation. Each operation is implemented by a method,plus there may be additional methods defined.

EXPRESS

No methods supported, but planned for version 2.

Open Distributed Processing

Treated as a hidden property of a Technology Language object. That is,methods are considered implementation-only related properties of an object.

Management Information Model

Not applicable.

SQL3

An SQL routine is basically a subprogram. A routine may be either aFUNCTION or a PROCEDURE. A routine reads or updates components of an ADTinstance or accesses any other parameter declared in its parameter list.A routine is specified by giving its name, its parameters, a RETURNS clauseif it is a function, and a body. A parameter in the parameter list consistsof a parameter name, its data type, and whether it is IN, OUT, or INOUT(for functions, the parameters are always IN; the RETURNS clause specifiesthe data type of the result returned).

A routine may be either an SQL routine or an external routine. An SQLroutine has a body that is written completely in SQL. An external routinehas an externally-provided body written in some standard programming language.If the function is an SQL routine, its body is any SQL statement, includingcompound statements and control statements (see 11. Object Languages).A number of new statement types have been added in SQL3 in order to makeSQL computationally-complete enough so that ADT behavior can be completelyspecified in SQL.

Matisse

Methods are part of the Matisse metamodel. They are functions attachedto objects which are invoked by messages.

C++

The behavior of a C++ object is defined by its member functions.All objects of a particular class share the member functions for that class.Every member function for a class must be declared with a function prototypein the class declaration. This prototype lists the arguments for the memberfunction. C++ adds an additional argument, this, to the beginningof the argument list for every member function. The this argumentis a pointer to the individual object for which the member function isbeing called (and is similar in some respects to self in Smalltalk).The this argument is implicit; it does not have to be explicitlyincluded in the function's argument list, nor does it have to be providedwhen the function is called.

The keyword virtualpreceding a member function declaration indicates that the function canbe redefined in classes derived from the current class (subclasses). Avirtual member function for a class is called through a jump table associatedwith the class. This allows a derived class' member function to be correctlycalled even when the variable used to access it is declared as being ofa base type. Non-virtual member function calls are bound at compile time.The derived class member function can invoke the base class member functionif this is required.

The keyword staticpreceding a member function declaration indicates that the function hasno this pointer. Static member functions (for example) provide away to access static data members without needing an actual instance ofthe class (static data members are data members shared by all instancesof the class; these would be equivalent to the instance variables of aSmalltalk class object). A static member function can access nonstaticmembers of its class only if passed an instance of the class (using the. or ->member access operators to refer to the particular member).

OOCOBOL

The procedural code in an object is placed in methods. Each method hasits own method-name and its own Data Division and Procedure Division. Whena method is invoked, the procedural code it contains is executed. A methodis invoked by specifying a reference to the object and the name of themethod. A method may specify parameters and a returning item. Data definedwithin a method is local to that method.

The structure of a method definition is:

IDENTIFICATION DIVISION. METHOD-ID. method-name-1   { PUBLIC     } IS { RESTRICTED } [PROTOTYPE] [OF [CLASS-OBJECT OF] class-name-1]    { PRIVATE    } [Method Environment Division] [DATA DIVISION. Method Data Definitions][PROCEDURE DIVISION [       {{ INPUT  }             }     ] [ USING {{ OUTPUT } data-name-1 } ... ] RETURNING data-name-2]. [       {{ I-O    }             }     ] Method Procedure Statements] END METHOD method-name-1.

Smalltalk

A method is the executable code rendered in the class and executed inthe context of an object instance. It defines how to perform an operationin the object instance. It is made up of a message pattern that is usedto match against incoming messages, temporary variables, and a sequenceof instructions. A method execution is triggered when message is receivedthat matches the methods' message pattern.

Cecil

In Cecil, a method declaration has the general form

method name(x1@obj1:type1,...,xn@objn:typen): typer{body}

There is no implicit selfformal argument; all formal arguments of a method are listed explicitly.A method specifies the kinds of arguments for which its code is designedto work. For each formal argument of a method, the programmer may specifythat the method is applicable only to actual arguments that are implementedor represented in a particular way, i.e., that are equal to or inheritfrom a particular object, called an argument specializer (recallthat Cecil is prototype-based (classless), and thus objects inherit fromother objects, rather than classes inheriting from classes). In the declarationabove, the obji represent argument specializers.

As indicated by the syntax above, argument specializers are distinctfrom type declarations. Argument specializers restrict the allowed implementationsof actual arguments, and are used as part of method lookup to locate asuitable method to handle a message send (see entry under 2.3 messages).On the other hand, type declarations require that certain operations besupported by argument objects, but place no constraints on how those operationsare implemented. Type declarations have no effect on method lookup.

Argument specializers are optional, and zero, one, or several (or all)of a method's arguments may be specialized. If zero arguments are specialized,the method acts like a conventional undispatched function or procedure.If only the first argument is specialized, the method acts like a normalsingly-dispatched method in a language such as Smalltalk. If several argumentsare specialized, the method is a multi-method (a method selectedon the basis of more than one argument) as supported in a language suchas CLOS. Callers which send a particular message to a group of argumentsneed not be aware of the collection of methods that might handle the messageor which arguments of the methods are specialized, if any. Methods maybe overloaded, i.e., there may be many methods with the same name, as longas the methods with the same name and number of arguments differ in theirargument specializers. Methods with different numbers of arguments areindependent; the system considers the number of arguments to effectivelybe part of the method's name.

Methods and objects are effectively connected through the methods' argumentspecializers. The methods in the system with the same name have no explicitconnection or relationship beyond the programmer's intentions. This isin contrast to the approach used, e.g., in CLOS, of linking all multi-methodswith the same name into a single generic function object. In Cecil, methodsare closely associated with their specializing objects (i.e., the objectswhose implementations include the methods), and only weakly connected witheach other. This approach to multi-methods permits viewing objects andtheir connected methods as a unit which implements a data abstraction;the methods defined for a particular object are always directly accessiblefrom the object. The mental image required is that of a graph of relationshipsamong objects and methods. Consequently, Cecil requires a graphical interactiveprogramming environment that can display these relationships and dynamically-varyingviews of them. For example, this environment could show objects on thescreen, with their associated multi-methods "contained" withinthe objects. The same multi-method could be viewed from each of its specializingobjects.

The following group of object declaration skeletons illustrate a simple(instance) inheritance hierarchy, together with some differently-specializedmethod definitions [Cha93]. These illustrate how methods implementing the"+" (addition)operator can be specialized to work on different combinations of argumentimplementations.

object int inherits number;
method +(@int, @int) {abstract} [*children must provide implementation]

object small_int inherits int, prim_int;
method +(x@small_int, y@small_int) {*codeof method*}
method +(x@small_int, y@big_int) {
*code of method*}

object big_int inherits int;
method +(x@big_int, y@big_int) {*codeof method*}
method +(x@big_int, y@small_int) {
*code of method*}

object zero inherits int;
method +(@zero, x) {x} [*zeroplus x is x]
method +(x, @zero) {x}
method +(z@zero, @zero) {z}

SELF

See entries under 2. Objects, and 2.1 operations.

System Object Model (SOM)

Methods are invoked on SOM objects. Methods can be relocated upwardin the class hierarchy without requiring the client to be re-compiled.SOM supports three different method dispatching mechanisms; offset, nameresolution, and dispatch function resolution.

The "offset resolution" mechanism implies a static schemefor typing objects and is roughly equivalent to the C++ virtual functionconcept. It offers the best performance characteristics for SOM methodresolution at a cost of some loss in flexibility.

This form of method resolution supports polymorphism that is based onthe derivation of the object's class.

Name resolution supports access to objects whose class is not knownat compile time, and permits polymorphism based on the protocols that anobject supports, rather than its derivation.

The "dispatch function" resolution is a feature of SOM thatpermits method resolution to be based on arbitrary rules known only inthe domain of the receiving object.

Dispatch function resolution is a completely dynamic mechanism thatpermits run time type checking, and open-ended forms of polymorphism.

A distinguishing feature of SOM is that all 3 forms of method resolutionare complementary and can be intermixed within client programs.

OLE Component Object Model

Methods in the Component Object Model are essentially equivalent toC++ member functions.

Analysis and Design Methods

SA: The concept 'method' is not usedin analysis.

CA: Service. A Service is a specificbehavior that an object is responsible for exhibiting. It is possible forthe receiver of a message to return a result and then continue to takeongoing action. A service can have trigger and terminate constraints, sothat it can activate itself without the need for a message to be sent toit.

RA: "A method is the implementationof an operation for a [particular] class."

JA: The concept 'method' is not usedin analysis. However, "[e]ach object [instance] is able to receivea specified number of stimuli. The object interprets this stimulus andperforms an operation or, perhaps, directly accesses a variable. In Smalltalk,this stimulus is called a message and the operation executed as a resultof receiving a message is called a method."

WD: "A method is a step-by-stepalgorithm executed in response to receiving a message whose name matchesthe name of the method."

MD: The term 'method' is not used. Thefeatures of classes include routines, which may be procedures or functions.

EA: The term 'method' is not used inthis method of analysis.

FA: "The analysis concept of objectdoes not include any notion of method interface. Methods are the meanswhereby objects communicate to perform some task. In the analysis phase,we concentrate on specifying what task a system has to perform. Discussionof object communication is postponed to the design phase."

FD: "When a message is sent, thereceiver invokes the corresponding method in the interface. [The appearancein an object interaction graph of a] message m to a server object C meansthat all objects of class C will include a method corresponding to m inthe method interface. Each method invocation may alter object attributesand return a result. "

OA: "A method is a processing specificationfor an operation." "An operation may have more than one methoddefined for it."

BD: "The terms message, method,and operation are usually interchangeable." See 2.1 operations.

HA: "A method implements a serviceby calculation (as opposed to storage)."

NA: Not used. Defined as: "Method(of a class)[:] A class feature." ['Method' is used by the authorsin the sense of 'a method of analysis and design.']


features matrixintro page