Human above all, with pathos, weaknesses and grumpy at times. Speak for myself; think out loud. Direct, seemingly hard faced. Urged to fix things. Am fortunate.
On Reusability (part 1) Misconceptions
Or why extracting a method is overrated and abused
One of the most frequent eureka moments we get as developers when writing code is when finding a method to extract in order to reuse it.
In an OO world however there is only as much gain since you can only use that method within that class. The problem resides in that a function is not a first class citizen.
Simply put, you need to carry the class that defines that method in every place you want to use it. This is easier said than done though depending on how you’ve designed your class. Especially if you’ve assigned more than 1 responsibilities to it.
So what you end up doing “at best” is introduce a static method, at worst copy and paste. There is a real issue here though and that is failing to identify a class that has manifest in your code leading to an explosion of methods.
This not only makes your API hard to use but also forces you to write more, sometimes even complicated code. Solely on the fact that in an OO world you have the concept of class relationships which is equally important to the class.
When you see procedural code, you only think procedural. So next time you start coding, look for the class!
Try it with your code to see what objects you come up with and how a correctly identified class simplifies things.