I currently have a number of classes (~20) that all do the same thing (abstractly), namely, generate an instance of a particular class from an xml file.
The way that they use the content of the xml file varies quite a bit, and the data gets stored into different substructures (fields, groups, etc) that are shared across the classes, so I took all of the parsing and field information out of the files, and created a helper class (as is the final constructed type)
All of the above classes and methods are static, as they have no need to contain any state.
I then wanted to have all the classes derive from one common class so that I am not referencing a seemingly unrelated class constantly, only to discover that inheritance and static do not work together well.
What is the appropriate way of setting this up? Its bascially a large set of factory methods for a type that require no state.
Update: The control flow is currently as follows:
- Pick one of ~20 factory methods
- Read in an XML file (all tags, attributes are the same across the files, but the files are distict across the methods).
- Convert the content in the XML files to a class that has some data structures as members (
List<Field>, List<Group>, Dictionary<string,string>etc). These data structures use types that are nested in the helper.
- Add these collections to the uninitialized object.
- Return the object to caller.
Right now, the 20 factory methods are thier own static classes, and all return objects of the same type, as even though there might be some semantic difference between the "types" all of the memebers and functions are the same. The code that parses the XML file is in a helper, as this logic is common to all of the factory methods. Step 3 has to be different for all the methods, so that part is found in the static classes.