I have C++ class Foo
:
class Foo
{
public:
[constructor, methods]
private:
[methods, data members]
};
I want to add to class Foo
the possibility for it to be constructed by reading data from a text file. The code for reading such data is complicated enough that it requires, in addition to a new constructor, several new private methods and data members:
class Foo
{
public:
[constructor, methods]
Foo(const std::string& filePath); // new constructor - constructs a Foo from a text file
private:
[methods, data members]
[several methods used for text file parsing] // new methods
[several data members used for text file parsing] // new data members
};
This works, but I feel it would be better to isolate the new parsing code and data members into their own entity.
What would be an adequate design pattern in order to achieve this goal?
Aucun commentaire:
Enregistrer un commentaire