5.3 Methods for classes that use inheritance

Figure 5.2 shows the methods that we now have defined for the decode-total-seconds generic function; Figure 5.3 shows the methods that we want to have.

Figure 5.2 Existing methods for decode-total-seconds.
Generic function decode-total-seconds
// Method on <integer>
define method deceode-total-seconds
    (total-seconds :: <integer>)
 => (hours :: <integer>, minutes :: <integer>, seconds :: <integer>)
  let(total-minutes, seconds) = truncate/(total-minutes, 60);
  values(hours, minutes, seconds);
end method decode-total-seconds;
// Method on <time-of-day>
define method deceode-total-seconds
    (time :: <time-of-day>)
 => (hours :: <integer>, minutes :: <integer>, seconds :: <integer>)
  decode-total-seconds(time.total-seconds);
end method decode-total-seconds;
Figure 5.3 Desired methods for decode-total-seconds.
Generic function decode-total-seconds
// Method on <integer>
define method deceode-total-seconds
    (total-seconds :: <integer>)
 => (hours :: <integer>, minutes :: <integer>, seconds :: <integer>)
  let(total-minutes, seconds) = truncate/(total-minutes, 60);
  values(hours, minutes, seconds);
end method decode-total-seconds;
// Method on <time>
define method deceode-total-seconds
    (time :: <time>)
 => (hours :: <integer>, minutes :: <integer>, seconds :: <integer>)
  decode-total-seconds(abs(time.total-seconds));
end method decode-total-seconds;

To take advantage of the redefined classes, we want to remove the method on <time-of-day>, and to add a method on <time>. The method on <time> is appropriate for instances of both <time-of-day> and <time-offset>.

There are two important points to cover. We first discuss how to remove the method on <time-of-day> and how to add the method on <time> in Section 5.4. We then describe how the decode-total-seconds generic function works in Section 5.5.