me.at.coding
me.at.coding

Reputation: 17786

Realize modular architecture / simple plugin system

I wrote a simple program taking some commands from a XML file, executing it, checkings for errors of the commands, reporting back by mail etc. An entry for a command looks e.g. like this:

<command>C:\Program Files\Test\test.exe /xyz</command>

Now I want to introduce some kind of plugins:

<command myPlugin1="abc,1" myPlugin2="def">C:\Program Files\Test\test.exe /xyz</command>

I thought about writing the plugins as a Java class implementing some interface or subclassing some Plugin class, then having a method like

pluginExec(List<String> parameters, String command)

that gets passed the parameters (e.g. abc,1) and the command (C:\Program Files\Test\test.exe /xyz). Then maybe take all attribute names of the command tag, therefore myPlugin1 and myPlugin2, then search for a class with the same name as the attribute on myapp.plugins namespace and call pluginExec(...).

Any better ideas on this? I guess with my idea I need some kind of reflection, is there a way without it? The application is a private tool, no need to be able to add plugins without recompiling the software. I just don't want to change the code everytime, I just want to plug in my new plugin class.

Upvotes: 0

Views: 173

Answers (1)

Dan D.
Dan D.

Reputation: 32391

If your plugin based program you develop will not grow a lot in the next future then your design is fine.

However, if you expect it to grow and you expect to add multiple features to it than I suggest you try Java standards like OSGi.

Upvotes: 1

Related Questions