Modules and libraries provide the structure of a Dylan program. Modules represent namespaces and control access to objects and functions. Libraries contain modules, and act as units of compilation in a finished Dylan program.
Modules import the symbols of other modules and export their own. The dependencies between modules must form a directed, acyclic graph. Two modules may not use each other, and no circular dependencies may exist.
Modules only export variables. Since the names of classes and generic functions are actually stored in variables, this represents no hardship. A sample module containing the vehicle classes from earlier chapters might resemble:
define module Vehicles use Dylan; export <vehicle>, serial-number, owner, owner-setter, tax, <car>, <truck>, capacity; end module;
Like all normal modules, this one uses the Dylan module, which contains all of the standard built-in functions and classes. In turn, the Vehicles module exports all three of the vehicle classes, the generic function tax, several getter functions and a single setter function.
To control access to a slot, export some combination of its getter and setter functions. To make a slot public, export both. To make it read-only, export just the getter function. To make it private, export neither. In the above example, the slot serial-number is read-only, while the slot owner is public.
Note that when some module adds a method to a generic function, the change affects all modules using that function. The new method actually gets added into the variable representing the generic function. Since the variable has been previously exported, all clients can access the new value.