I am looking for some help wrapping my head around the class design.
I am working on a Class Hierarchy to handle our data transfer communication within our company and am not sure how to configure the classes.
The basic design is this:
Transport Method - Parent Class
DirectSQL, HTTP, Local - Child Classes
RequestSN, Save Data - Methods
Now, within the Child Class and method, the data format has the option of being XML, JSON, SQL or TEXT.
For example, I could use the Save Data method under HTTP, and the Save Data could then be implemented using XML, JSON, etc data formats.
I am struggling with where to put the Data Format class. Do I need to implement Save Data - XML, Save Data - SQL, Save Data JSON, etc for each method, which essentially does away with the data format class (in my opinion)?
Do I add the DataFormat class as private data of the Transport Method class, and then access the data member in each of the methods?
I would have a separate formatter class heirarchy with an abstract parent and specific children for each of them.
Then you can store a copy in the transport class that the child classes can use to perform the formatting.
At some point, you would have to decide the right formatter and set it in the transport class, normally wherever you create this.
This keeps it inline with the SOLID principles as well, if your not familiar with them it is worth reading around online - there is lots of material on them.
I recommend something along the lines of the bridge pattern from the GOF.
You can implement it exactly as James mentions.