struct i_foo * foobar_foo(void); //返回接口指针
struct foo_object * foo_create(struct i_foo *iface, void *data);
void foo_release(struct foo_object *);
void foo_dosomething(struct foo_object *);
struct foo_object
{
struct i_foo * vtbl;
void * data; void * others;
};
struct i_foo
{
void (*dosomething)(void *);
};
struct data;
struct data * data_create(void);
void data_release(struct data *);
struct foo_object * foo_create(struct i_foo *iface, void *data);
{
struct foo_object temp;
temp.vtbl = iface;
temp.data = data;
return &temp;
};
struct foo_object * fobj = foo_create(foobar_foo() , data_create());
void foo_dosomething(struct foo_object *fobj)
{
fobj->vtbl->dosomething(fobj->data); // do something else
}