2

我想编写一个程序,该程序将通过给定的输入目录递归运行,并将对其遇到的内容执行预定义的任务。我希望它是健壮的,这样我就可以开发应用程序,如果我想在将来添加另一个行为,就不必进入核心代码。

在我看来,每个要执行的任务都应该在一个类中实现,并且应该有一个配置文件将类映射到文件类型,例如。

我对如何实现这一点有一些想法,但不能完全将其形成一个解决方案。

这应该通过依赖注入来完成吗?如果是这样,哪些简单的 DI 框架适合这个?

或者也许应该通过读取配置文件并加载那里定义的类来完成?

4

1 回答 1

0

Depending on how complex you need it, you might take a look at http://static.springsource.org/spring-batch/

If you need a simpler approach you could expose a "command-like" interface to be implemented by all your processing classes, and some kind of factory class that will instantiate these implementations based on your mapping.
This way you'll be working mainly with the interface by calling the factory for each file, and then invoking the "process" method.
Adding new tasks should be as easy as creating a new implementation of the interface and adding it to the mapping file.

Cheers

于 2012-04-10T15:18:53.040 回答