3.2.2 Relationship between classes and methods
The relationship between classes and methods in Dylan is different from that in C++ and Smalltalk, among other languages.
Comparison to C++ and Smalltalk: In C++ and Smalltalk, a class contains the equivalent of methods. In Dylan, a class does not contain methods; instead, a method belongs to a generic function. This design decision enables these powerful features of Dylan:
|
In Dylan, a method belongs to a generic function, as shown in Figure 3.1, page 30. Although methods are independent of classes, methods operate on instances of classes. A method states the types of objects for which it is applicable by the type constraint of each of its required parameters. Consider the say-greeting method defined earlier:
define method say-greeting (greeting :: <integer>);
format-out("Your lucky number is %s.\n", greeting);
end;
This method operates on instances of the <integer> class. Notice how easy and convenient it is to define a method intended for use on the built-in class <integer>.




