I am programming in Python. I have several complicated/hard-to-understand XML files that describe the structure of an election. I am trying to write a python wrapper that makes it easy to access this data.
The structure of the entities I am trying to model is: there is an election. Elections have races. Races consist of candidates who get results in precincts. Precincts are organized into counties.
I first built this so that the election class holds an array of races objects which hold arrays of candidate objects and result objects. But now I am starting to write unit tests and it is hard to test the candidates or races (because they are coupled to the election).
The election has information about the races, which it feeds to each race's constructor. The race has information about the candidates (i.e. what they are running for), which it feeds to their constructors.
I know that it is in general a good idea to have decoupled classes but in this case there is a natural hierarchy in the domain and I am wondering to what extent it makes sense to have my code reflect this hierarchy. The ultimate goal of this is to write out "results" in json (for a web app) that are much, much easier to parse than the XML. The results will change every few minutes as they come in (on a new election xml file). I'd love some design advice.