4.1 User interface

The user interface of an ADT is a list of operations that can be performed on objects of the ADT. Let us consider an ADT that deals with fractions. Again, we need to think about what we want to do with fractions, not how we want to perform the operations.

The user interface of an ADT is published in a header (.h) file. In this example, we may define the following:

struct Frac {
};

struct Frac *newFrac(void);
void delFrac(struct Frac *);
void Frac_set(struct Frac *n1, int num, int den);
void Frac_add(struct Frac *n1, struct Frac *n2, struct Frac *sum);
void Frac_sub(struct Frac *n1, struct Frac *n2, struct Frac *diff);
void Frac_mult(struct Frac *n1, struct Frac *n2, struct Frac *product);
void Frac_div(struct Frac *n1, struct Frac *n2, struct Frac *quotient);
float Frac_value(struct Frac *f);
void Frac_simplify(struct Frac *f);
unsigned Frac_get_numerator(struct Frac *f);
void Frac_set_numerator(struct Frac *f, unsigned numerator);
unsigned Frac_get_denominator(struct Frac *f);
void Frac_set_denominator(struct Frac *f, unsigned denominator);



Copyright © 2006-09-07 by Tak Auyeung