Looking for a pattern for class creation & configuration based on input
params
I need to create a complex configuration object based on the values of
params I receive.
My inputs are 2 simple variables, and a configuration object. The
combination of the 2 variables, and the config object's internals will
determine the configuration of the output class (which is always the same
type)
Doing this with simple if-else it'd look like this:
if (a == 1 && b == 1) {
//do some testing on the input object, configure and return the output object
else if (a == 2 && b == 1) {
//do some different testing on the input, configure and return the output.
}
and on.
There are about 5 different values that a & b could hold and depending on
the values of a & b, I'm going to have to test for different things within
the input object.
I'm not really sure of the best way to solve this. My first thought is to
have some kind of Command Pattern with a method like:
public OutputConfig execute(InputConfig config);
and store my potential a & b combinations in Map<Pair<A,B>, Command> for
lookup.
I feel like I'm looking for some Factory / Command / Builder pattern but
not sure of the best way to implement this.
Thanks in advance.
No comments:
Post a Comment