I am currently working on project which requires parsing different types of files. The content of the files will populate the classes.
eg: file1 populate content of class1, file2 populate content of class2, etc.
My question is where should the parsing logic of the file go?
1st option
: If I place the parsing logic inside the class then the class becomes really huge, because currently the class itself is ~400 lines and will grow in the future. The advantage of this way is things are really simple, I could use operator>>, etc.
2nd option
: Create a new class that takes std::istream
and class reference, do the parsing logic there and populate the class. The advantage of this way of doing is that if the class remains the same but formatting of the file changes,
eg: `file1 populate content of class1 or file1-v2 populate content of class1`
I have to use polymorphism to change the parsing logic and keep the design simple. Disadvantage of this option is, it's a little complex but I can live with it.
Which option do you think is better or is there any other better option?