CS202 Computer Science II
FAQ Newsboard  Telnet Email TA Lectures Assignments Man pages Help

Modules


Chapter 2 in textbook.

A module is a generalization of a function. It is a collection of related items like functions, constants, variables, and types, packaged into one separately compiled unit.

The stack module specifies and implements the Abstract Data Type (ADT) called a stack.

I have implemented a stack module for you. The specification of a stack is your (the user's) view of the module. The implementation of the stack is my (the implementer's) view of the module.

Another way of saying this is that the specification of a stack is the PUBLIC view of the module. The implementation of the stack is the PRIVATE view of the module.

A well designed module ENCAPSULATES private code and data hiding them from the user/public. Code that uses a module is called a CLIENT.

How do we do Modules in C/C++

You need Separate Compilation of program units and you need an interface between the public and private parts.

More specifically, in C++ a module is represented as a pair of files

You can link your program files (as1.cpp) with the module in a variety of ways.
%	g++ -o paren as1.cpp stack.o
or
%	g++ -c -Wall as1.cpp
%	g++ -o paren as1.o stack.o
or create a makefile (we'll learn how soon, for now use the one I supplied you with) and simple type make
%	make