jeudi 21 novembre 2019

Doesn't having more than 1 method break the Single Responsibility Principle?

I am quite confused with the Single Responsibility Principle. The Principle states that there should only be one reason for the class to change.

The problem which I am facing is, any change to a method or any logic change in doing things would change the class. For example, consider the following class:

class Person{
    public void eat(){ };
    public void walk(){ };
    public void breathe(){ };
    public void run(){ };
    public void driveCar(Car car){ };
}

Uncle Bob describes it as there should ONLY be a single person/Actor responsible for the change. I have the following two questions:

  1. For the above class who is the actor/Person who can be responsible for change?
  2. Wouldn't any change in the logic of eating, breathing or walking change the class Person? So doesn't that mean that every method is a reason to change as it's logic to doing things might change?

Thanks

Aucun commentaire:

Enregistrer un commentaire