13.4 Module definition
Enough theory. Let's see how modules and libraries can be used in practice by considering the classes and methods for representing and manipulating times that we defined in Chapter 8, A Simple Library, and showing how they might be packaged into a reusable software component.
First, let's examine what the external protocol of our time library might be. We have defined two kinds of time that can be created: <time-of-day> and <time-offset>. We have a generic function for printing times, say, and one, perhaps not so obvious, utility function for creating new times, encode-total-seconds.
We define a method, \+, for adding times, but a method is not a protocol. The protocol for the generic function \+ is defined by the Dylan library, which already exports it, for any Dylan program. When we define our method for adding times, we are extending that protocol; we are not creating a new one.
The decode-total-seconds function, the <sixty-unit> class, and several other functions are used internally only, so they are not part of the external protocol.
Although <time> is used internally only within our library, it is good practice to make abstract superclasses such as <time> part of a library interface. When we do so, a client of the library that does not care which specific kind of time is being manipulated can simply use <time>.
Thus, five items (<time>, <time-of-day>, <time-offset>, say, and encode-total-seconds) define the external protocol of the time library.




