http://rubyblog.pro/2017/05/solid-single-responsibility-principle-by-example
url =
log_request(, url)
posts = request_handler.send_request(url)
response_processor.process(posts, Post, mapping)
end
# ...
end
It works :)
We could even extract logging logic into RequestHandler. But for now I think we did a really good job with refactoring initial class with 4 responsibilities. Probably naming could be improved as well, but the general idea here is to have 3 reusable classes instead of 1 class with 4 responsibilities.
Let me know if you have good examples of Single Responsibility implementation. Also, I'll appreciate any feedback about this article. I included a lot of code here, let me know if it's easy to read.
Thanks for reading and happy coding!
Read more about SOLID Principles in case if you missed it: