FAQ | Newsboard | Telnet | Email TA | Lectures | Assignments | Man pages | Help |
---|
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.
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
For example, for our first assignment we have:
stack.has the specification file. You use the specification file as an interface between the public and private parts of your program by including it (#include "stack.h") in your source files, wherever you need to use it.
For example, we have for as1 :
stack.cpphowever, you don't need to see the implementation file, you only need to see the module as an object file, a separately compiled file corresponding to stack.cpp called stack.o
I produced stack.o by using;
% g++ -c -Wall stack.cppwhich produced stack.o
% g++ -o paren as1.cpp stack.oor
% g++ -c -Wall as1.cpp % g++ -o paren as1.o stack.oor create a makefile (we'll learn how soon, for now use the one I supplied you with) and simple type make
% make