How to write a robust, customizable app for executing tasks on files?

92 views Asked by At

I want to write a program that will run recursively through a given input directory and will execute pre-defined tasks on what it encounters into. I want it to be robust, so that I can develop the app and don't have to go into the core code if I want to add another behavior in the future.

The way I see it, each task to perform should be implemented in a class, and there should be a configuration file mapping classes to file types, for example.

I have some idea of how to implement this but can't quite form it into a solution.

Should this be done with dependency injection? And if so, which simple DI frameworks suit for this?

Or maybe it should be done just with reading the configuration file and loading classes that are defined there?

1

There are 1 answers

0
Morfic On

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