As far as I know, when writing an application, it is better to separate the logic from the I / O interface. Those. to do some classes for logic, and others for input-output interface. What is the best way to establish relationships between these classes? Those. for example, I am writing an application that reads information from a file, converts it in some way, and then writes it to another file. Those. I have two classes of the same one describing logic, and the other describing receiving and writing to a file. What kind of relationship between them is better to establish.
|
1 answer
One option is to define input / output operators for the classes for the classes.
friend std::ostream& operator<< (std::ostream&, const my_class&); friend std::istream& operator>> (std::istream&, my_class&);
- Unfortunately, I cannot overload the operators ... And I also do not recommend making friends by condition. And so I decided to make a class MANADGER which will be like a wrapper over the class CALC (CALC - class with logic), and in which I / O methods will be implemented. Those. in the MANADGER class, a field with an object of the CALC class is declared, as well as the necessary methods for input-output. Accordingly, I am tormented by the question, is this the right decision, or are there more preferred methods, how can this be organized? - shc345
|