0

What if I have a class X that does the following:

  • Read a file (within its own class).
  • Parses the file by calling a Parse class
  • Processing the parsed file by calling a Process class
  • Outputting by calling an Output class

I would assume the single responsibility is reading the file, but the other functions (parsing, processing, outputting) are also done by this class (by calling other classes.

Or what if the reading part would be done in a separate class too, and the class X only calls these 4 classes without doing something itself (like a manager)? What is then the responsibility? Is then the Single responsibility 'Managing the reading, parsing, processing output of a file' a responsibility?

2

The responsibility of this class is to retrieve information and output it. In other words, all of the things it does are its responsibility.

However, how it does this is its own business and of no interest to its users. For instance, most C programs that produce screen output will eventually call printf, whose code lives in the standard library rather than in the program's source code. That doesn't change the fact that the program's task is to print things, it just means, that it achieves this task by code reuse.

The task of the custom program might be described as "Print this month's salres reports", while that task to printf is "Print whatever strings and formats you are called with". You see that the helper code's task is a (small) part of the greater task, just as printing this report may be a small pat of th greater task eachieved by the entire application.

  • Thanks, just was a bit confused if that 'complete' responsibility was also considered a 'single responsibility'; guess it is (what I also expected). – Michel Keijzers Feb 4 '16 at 12:39

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.