6.1.3 Method for adding other kinds of times
We have already defined methods for adding the kinds of time that it makes sense to add together. It is not logical to add one time of day to another time of day — what would three o'clock plus two o'clock mean? Someone could create another concrete subclass of <time>, without providing any methods for adding that time to other times. If someone tries to add times that we do not intend them to add, the result will be a "No applicable method" error.
We could provide a method whose sole purpose is to give more information to the user than "No applicable method" when + is called on two times that cannot be added, because there is no applicable method for adding them. We define such a method here:
// Method on <time>, <time>
define method \+ (time1 :: <time>, time2 :: <time>)
error("Sorry, we can't add a %s to a %s.",
object-class(time1), object-class(time2));
end method \+;
This method is called only when the arguments are both general instances of <time>, and none of the more specific methods are applicable to the arguments. The error function signals an error. For more information about signaling and handling errors, see Chapter 20, Exceptions.
Note: This method is useful for explaining how method dispatch works for multimethods, but it does not really give the user any more useful information than that supplied by the "No applicable method" error. Therefore, we define the method in this chapter, but do not include it as part of the final library.




