Purpose of simple wrapper function in C -
in ex26 of 'learn c hard way' in db.c
file zed defines 2 functions:
static file *db_open(const char *path, const char *mode) { return fopen(path, mode); } static void db_close(file *db) { fclose(db); }
i have hard time understanding purpose/need wrapping these simple calls fopen
, fclose
. are, if any, advantages of wrapping simple functions, example given above?
in particular case wrapper used hide detail db_open
, db_read
or db_close
map file operations.
this approach implements abstraction layer through database related functions accessed. provides modularity, may later allow adding more methods open/read/close databases.
as explained michael kohne in comments, wrapper should improved totally hide e.g. type of file *db
, substituting struct db_context *context;
.
Comments
Post a Comment