From Wikipedia on Single responsibility principle SoC
... class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility
class or module should have one, and only one, responsibility . As an example, consider a module that compiles and prints a report. Imagine such a module can be changed for two reasons. First, the content of the report could change. Second, the format of the report could change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times.
The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Continuing with the foregoing example, if there is a change to the report compilation process, there is greater danger that the printing code will break if it is part of the same class.
Is there a rule or general guideline on how to define responsibility of methods in class?
When we talk about objects inanimate objects its easy to see compile report and print report is two different responsibilities. However when it comes to animate objects like dog it becomes not so evident what methods are different in nature.
Say you have:
class dog {
public $breed;
public $age;
public $color;
function bark($loudness) (
...
)
function pee($amount) (
...
)
function run($speed, $distance, $direction) (
...
)
function growl() (
...
)
function drink() (
...
)
}
how can you tell what responsibility should be in a separate class?