I was thinking of a loader class and came up with two different approaches.
class Loader{
public:
Loader(const Path& path);
File load() const;
private:
Path path_;
};
vs
class Loader{
public:
Loader();
File load(const Path& path) const;
};
With the first approach, I need one Loader per file and the Loader class represents a state. With the second one, I can load different Files with one loader class.
Besides these obvious differences which approach would you choose and why or is there a third maybe superiour way?
There are other approaches as well.
If you don’t maintain any state in the
Loaderclass when loading a file, then you can simply write a free functionOr you can make the function
staticif you want it to be a member functionSometimes such solutions entirely depend on the situation, and sometimes on company/programmer’s personal preferences and taste. There is no one best solution as such!
You can even choose to write the
loadfunction in theFileclass itself:In this, maybe, you would want to change the name of the function:
open()seems better thanload().