根据wiki,
依赖项是可以使用的对象(作为服务)。
Image processing应用程序是OOP范例样式C语法,它解决了4个角色,如下所示。
handlers.h
)typedef struct {
int (*canHandle) (char *);
int (*drawImage)(char *);
int (*savefile)(char *);
}imageHandler;
gifhandler.c
)imageHandler gifhandler = {
gif_canHandle,
gif_drawImage,
gif_savefile
};
config.c
)//gifhandler.c - dependency
int _init(){
printf(" registering gifhandler \n");
reg_handler(&gifhandler);
return 0;
}
//config.c
imageHandler *imagehandlers[10];
int reg_handler(imageHandler *ih){
// we need to perform checks here.
imagehandlers[libs] = ih;
libs++;
return TRUE;
}
// config.c
int init_handlers(){
.....
soptr = dlopen(so_name,RTLD_NOW);
....
}
UI.C
)// UI.C
switch(choice){
case 1:
vdrawImage(filename);
break;
case 2:
vsavefile(filename);
break;
}
// viml.c
int vdrawImage(char *filename){
...
handleno = find_handler(filename);
...
ih=imagehandlers[handleno];
ih->drawImage(filename);
return FALSE;
}
// viml.c
int vsavefile(char *newfilename ){
...
handleno = find_handler(newfilename);
...
ih=imagehandlers[handleno];
ih->savefile(newfilename);
}
1)要在Dependency容器中添加新依赖项(libxyzhandl.so.1
),只需要在config.txt
中添加一个新条目,如下所示:
的config.txt
./libgifhandl.so.1
./libtiffhandl.so.1
2)./libxyzhandl.so.1
提供的新服务将由Dependency容器包含,无需重新编译应用程序。
3)除libxyzhandl.so
的源代码外,不需要测试完整的应用程序。
所以,如果config.txt
变空,那么,应用程序什么都不做,除了说We cannot handle this kind of files
,显示here,任何输入(图像文件)。
以下是呼叫流程的可视化,
题:
1)依赖容器是否与IOC容器不同?
2)Spring IOC容器是否提供了比仅维护依赖项更多的功能?