The problem is the following: I have to download a set of JSON files and convert them to a certain format. There are 5 output formats (Let's call them A, B, C, D, E) and all of the downloaded json files are going to be in of of two formats (call them J1, and J2).
So once I decide whether I am downloading J1 or J2 type of files, I should be able to convert them into one of the 5 formats. Basically this means that there are potentially 10 different conversions possible.
I was wondering how to better design this application the current setup is the following:
- Converter class - which implements common behaviors.
- An interface which all strategies should have
- 10 different strategies. from J1 to (A,B,C,D,E) and J2 to (A,B,C,D,E)
All 10 different strategies implement the interface of converting to necessary format, a Converter object contains a strategy which is set at run time when I understand exactly which one is required (based on user input)
This seems unbelievably sloppy, maybe I am not understanding the Design Pattern as necessary. If I have all the strategies implemented in different classes, they all have a convert
function, why should I bother to create a Converter object and initialize it with my chosen strategy, when I could simply make a ConcreteStrategy type of object and call the convert
function on them.