5.4 Redefinition of a method
It is important to understand that when you define a method, Dylan will do one of the following:
Add that method to the generic function (without affecting existing methods), if the parameter list of the new method is different from the parameter lists of all the existing methods.
Redefine an existing method of the generic function, if the parameter list of the new method is equivalent to the parameter list of one of the existing methods. (Although the concept of redefinition is not in the Dylan language, most Dylan development environments support redefinition.)
Two parameter lists are equivalent if the types of each required parameter are the same. A parameter with no type is the same as a parameter whose type is <object>. For example, the following parameter lists are equivalent:
(a :: <string>, b :: <integer>, c) (str :: <string>, num :: <integer>, any-old-thing :: <object>)
Assume that we are working in a listener, and already have defined the methods shown in Figure 5.2. Consider what happens when we define the method on <time>. The parameter list of the new method is not equivalent to the parameter list of any of the existing methods, so the new method is added to the generic function. Thus, decode-total-seconds has three methods: a method on <integer>, a method on <time-of-day>, and a method on <time>. The environment may offer a way to remove a method from a generic function. When we remove the definition of the method on <time-of-day> using the environment, the decode-total-seconds generic function contains only the desired methods, as shown in Figure 5.3. A typical browser will help you to find the methods to remove.
If, however, we are working in source files rather than in a listener, we simply need to remove the method on <time-of-day> with the editor, and to type in the method on <time>. When we next compile the file, the generic function will contain only the desired methods, as shown in Figure 5.3.
We can now call decode-total-seconds on instances of <time-of-day> and on instances of <time-offset>:
? decode-total-seconds(*your-time-of-day*); 8 30 59 ? decode-total-seconds(*your-time-offset*); 6 45 30
The result is as expected — decode-total-seconds returns the hours, minutes, and seconds. We now describe how this generic function works.




