Let’s say I have four classes A,B,C,D.
Each of those classes contains a Tree object. This tree object needs to be built according to information stored in files f_A, f_B, f_C, f_D, for classes A,B,C,D respectively.
So the tree in class A needs to be built according to f_A.
Now I think it is not a good idea for the Tree class doing file I/O.
One option would be that the Tree has a function buildFromString(String s) which takes the content of a file as a string and builds itself.
But again, I don’t think the Tree should do any String processing.
An alternative would be that for each class A,B,C,D we have a Tree builder Class, which takes a Tree object as a parameter, reads the corresponding file and builds the Tree.
Maybe a Factory pattern would help, but I don't see how to make use of it in this context.
But this introduces a lot of new classes.
What would be a clean way of building the trees from the files subject to which class they are instantiated from?
But this introduces a lot of new classes.
...so what?