In a previous post, I talked about the beauty of composition. Today, I want to extend on that with a beautiful enlightenment that I had. Lucky you, I am gonna share it, and you are reading it!
Breaking It Down
It is all about breaking those methods calls down!
Let’s assume you are building an application that authenticates with different services, like twitter, facebook, google, … etc. If you have this in your code, you’re doing it wrong (I used python because it’s easier to write):
Now, notice how you can achieve a much more modular design with even better readability:
I know, I could’ve used getattr, but that’s not the point. The point is how we managed to break the long method name into a nicely composited object!! This is actually the obvious example, let’s see a bit more challenging one:
You can see it now, can’t you ;) YES!! This is bad, and should be changed to:
I don’t think I will ever write anything in the blog of more value than this post… I desperately needed this advice ages ago.