My background is not in OOP so I would like a bit of advice please regarding a better structure for a couple of ‘modules’ I have written.
The 1st two ‘modules’ each have a function of reading an XML and turning it into a Dictionary in one case and a List of records in another.
The way I have written it now, each of these is a class and the calling function defines the result eg
private Dictionary<string, (string , string )> targetDict = new Dictionary<string, (string , string )>();
then calls the constructor
var myTargets = new readXML_Targets (targetDict);
which does all the work to load the resault directly into the parent’s declaration. Then the class could be destroyed.
I realise this is a very ‘functional’ view of the code.
Alternatively I could put the definition of the ‘result’ inside the class; the constructor can still do all the work to process and load the XML.
Then add a get() method that returns the result. I suppose doing it this way allows for more specific methods like get_entry_for(xx), but that is a bit its a bit nebulious for me.
In both these particular cases the ‘result’ is immutable so I would not envisage other methods being needed.
Your Advice ?
P.S. I have many more ‘modules’ to stitch in that do have full on OO methods.
JC