3 ms·
All methods are private except for the initializer and create_user. Therefore, there's no difference in terms of "implementation hiding (encapsulation)" betwee
by whstl 3y ago
All methods are private except for the initializer and create_user.
Therefore, there's no difference in terms of "implementation hiding (encapsulation)" between the original 4-line function [0] and the class I presented.
Also, there is no testability differences, unless you break encapsulation in your tests and test private methods directly with things like send(:find_admin_role). As much as this is seen in Ruby, this is not something that would pass a code review.
This class is just 9 methods in a trenchcoat pretending to be that 4-line function.
And in case you think this not a strawman example. I provide a real-world case in another message. [2]
[1] https://news.ycombinator.com/item?id=38492002 https://news.ycombinator.com/item?id=38492002
[2] https://news.ycombinator.com/item?id=38493809 https://news.ycombinator.com/item?id=38493809