-
Notifications
You must be signed in to change notification settings - Fork 4
Towards Greater Code Reuse
Code reuse is for me the holy grail of software. It is something we lost in large measure with the adoption of top-down development. And OO has only complicated the matter. For some time now I have advocated the use of factories and interfaces as a means of decoupling, but writing reusable code has continued to be a bit of a lost art. But then, I was a Java developer.
Having been exposed to Clojure, I've come to realize that a function is the smallest unit of reusable code, not a class. Simply moving logic from methods to functions (or to static methods, if you are still using Java) opens up a lot of possibilities. Mind, I still advocate the use of interfaces for method polymorphism, but limit method bodies to be little more than a call to a function or a property accessor.
Doing this allows us to avoid class extensions and mind-numbing class hierarchies. The code becomes much clearer, defining new classes becomes much easier, and the need to refactor the code is greatly diminished. And writing reusable functions is much easier than writing reusable classes.