← Back to Upcase

Sandy Metz Ruby Talk


(Charlieanna) #1

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.


(Patrik Bóna) #2

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.


(Charlieanna) #3

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?


(Burak) #4

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

http://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley/dp/0321721330


(Charlieanna) #5

Oh thanks. Checking it right now. :smile:


(Patrik Bóna) #6

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.


(Charlieanna) #7

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