4.3 Consumer

The consume of an ADT refers to the code that makes use of fractions. Such code should be a .c file. However, it cannot access members of struct Frac.

The consumer code may look like the following:

#include "frac.h"
...
  Frac *length, *width, *area;

  // create length, width and area
  length = newFrac();
  width = newFrac();
  area = newFrac();
  // initialize length, width
  Frac_mult(length, width, area);
  // ...

Any consumer source code needs to be compiled, and linked with an object file provided by the provider. In this example, for the consumer code to work, its object file must be linked with frac.o.



Copyright © 2006-09-07 by Tak Auyeung