Abstract Data Types in C

  • Interface declares operations, not data structure
  • Implementation is hidden from client (encapsulation)
  • Use features of programming language to ensure encapsulation

Common practice

  • Allocation and deallocation of data structure handled by module
  • Names of functions and variables begin with <modulename>_
  • Provide as much generality/flexibility in interface as possible
  • Use void pointers to allow polymorphism

#ifndef ARRAY_H

#define ARRAY_H

typedef struct Array *Array_T;

extern Array_T Array_new(void);

extern void Array_free(Array_T array);

extern void Array_insert(Array_T array, void *datap);

extern void Array_remove(Array_T array, void *datap);

猜你喜欢

转载自www.cnblogs.com/zjbfvfv/p/10329400.html