The purpose of this chapter is to elaborate on the composition abstraction for collecting sections of code under a single name. When the code in question is needed in the main program, only its name need be written. In Modula-2, composition is achieved by using the procedure mechanism, the code for which is placed in the declaration part of a module, and that can be used freely throughout the main program. On completing the chapter, the student should understand and be able to use the following:
General:
Procedures as data types
Realized in the Modula-2 notation:
procedure types
General:
code encapsulation, input and output parameters
Realized in the Modula-2 notation:
procedure value and variable parameters; formal and actual parameters
General:
Top-down design and planning is extended to breaking a problem into sub-tasks that are then encapsulated as separate sections of code and called upon as desired.
Realized in the Modula-2 notation:
procedures, function procedures, recursion