- 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);
原文地址:https://www.cnblogs.com/zjbfvfv/p/10329400.html
时间: 2024-10-11 16:58:45