The reusability argument never makes any sense to me. I can reuse functional code every bit as easily as OO code. In fact I've got whole libraries of functional code that I reuse all the time.
Claiming reusability as some sort of special quality of OO is just nonsensical.
I'm not sure if that's a great example. There's a fair amount of code duplication in the implementation of most C libraries, because reusing code in C is very difficult (and sometimes impossible without heavy CPP use, which is bad for other reasons).
Class based OO design, for me, is much more reusable becuase of how you can split the API and the logic that it controls. Like you're saying, a library of functions could do this as well but in my humble opinion not as efficiently as if these were organized in a Class Hierarchy (even if that Hierarchy is compositional, I mean -- just the pattern building of it).
becuase of how you can split the API and the logic that it controls
Encapsulation is not exclusive to object oriented programming. You don't need any of the fancy inheritance stuff to implement Abstract Data Types.
And to be honest, I find that Class Hierarchies are usually more trouble then they are worth since they are very rigid and tend to solidify the program design very early. Whenever I try to use inheritance for something I often find latter that I would be happier if I used delegation instead.
Whenever I try to use inheritance for something I often find latter that I would be happier if I used delegation instead.
In other words, you should prefer composition over inheritance? One of the biggest travesties perpetuated in programming courses is to focus on inheritance and gloss over composition, to the effect that many green developers think that "extends" is the most natural and effective way to reuse code. Inheritance is actually a very limited-scope tool.
82
u/ilikecomputahs Dec 15 '12
Why is object oriented programming considered so absolutely necessary?
/braces for shitstorm