I have a Java application that needs to process some data. The data starts off in format A.
The application consists of a number of modules which are each capable of processing data. But not every module supports the same kind of data as in- and output. Module 1 accepts data in format A and outputs it in format B. Module 2 accepts data in format B and outputs it in format C. Module 3 takes data in either format A or format C and outputs format B. Another one takes B or C and returns the same format it received the data in. And so on, you get the idea.
And as if this situation was'nt bad enough already, there are a lot of modules, each with their own in- and output formats. Some match, some don't. The modules could be executed in any order, and the order is provided at runtime by the user.
I need to make sure that the modules are in an order where every in- and output matches. How can I accomplish that? Is there maybe some design pattern I don't know of that solves this?
Basically, I need a way to retrieve in- and output format of a module, compare it to another one, and sometimes cast an object to the type I figured out.
I had a couple ideas like retrieving the parameter and return types via reflection, but some data formats involve nested Generics which are erased at compile time. And other things I came up with wouldn't get around the fact that I'd probably have to figure out what type to cast to at runtime if I applied them.
Any thoughts and directions would be appreciated.
Module
. I have to check whether the next module in line supports the format the data is currently in, and that at runtime since I can't tell what the next module is at compile-time.