Sandy Metz Ruby Talk

She talks about violating SRP when you have and in your specs file, that is, if you have a single class doing multiple things then you are violating the single responsibility principle.

There is also a rule in which you don’t test your private methods. So am I right in thinking that a class should have only one public method which the work it does or its sole responsibility like downloading a file but can have many private methods which help the class to download the file.

How can you decide what a class’s sole duty is? Because I feel each time you add a method(even private) you are creating a new responsibility of the class.

I do not think that you should have just one public method without violating SRP. Think about Robot and methods like move_left, move_right… You can have more such methods without violating SRP.

So when do you know you need to create a new class instead of just creating a new method and asking that method do the work?

you should check out the book by Sandi Metz called practical object oriented design which will give you a good idea of how you should design your classes, srp, dependencies, inheritance and much more

1 Like

Oh thanks. Checking it right now. :smile:

Well, I do not know ;). I just experiment a lot a delete the code… :wink: I’ve read the POODR too, but without practise it is not enough.

Ya true. I am finding it hard to read that book. Practising is the only way to understand it.