1

I am often in the following situation:

  • I have a config file, specifying the path to a resource file
  • This config file gets parsed and the values (e.g., file path) are stored in a ConfigStore object
  • A business logic object needs to content of the resource file.

Now who should actually read the resource file?

  1. ConfigStore
  2. The Business Logic Object
  3. A special parser
  4. ?

I don't like any of the 3 options: Both 1 and 2 violate the single responsibility principle, on the other hand, since file io is only a few lines, introducing a special parser class for this also seems like an overkill.

So who should read the file?

  • How complex are those operations and how much of what they're doing is similar to other operations in other objects? – whatsisname Apr 4 '17 at 21:33
1

How complex is parsing the config file? If it is very straightforward one time read of an XML or an .ini like file, just have ConfigStore read it.

What else does your ConfigStore do? Assuming it just provides getters for the information, I'd argue that the responsibility is to read the config file(s).

SRP is poorly understood and highly overrated. And simple getters are not a "responsibility".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.