by programminggeek · 14y ago · 0 comments
For example, say you have an object that holds some strings and numbers and it has getters and setters on it. How is that different than a Hash? Is that object oriented? If you add a couple helper methods to said object is it more OOP if you still are using getters and setters?
There is a fundamental difference between treating OOP as a bunch of classes that contain basically procedural code vs treating them as objects that are things that do things.
Treated the way it often is, OOP is not that useful for anything other than namespacing and creating ridiculous hierarchy structures just because "it's oop" and inheritance lets humans do what they love to do - name and categorize things.
If you treat objects in OOP as "things", I think it is more useful and interesting than treating objects as containers. Either way, not all code needs to be OOP at all.
Of course this is the most degenerate case of an object, so pointing to this as an counter-argument to OOP seems rather specious. The typical case is that the data being encapsulated is related to each other in some way, and thus having a restricted set of operations on the object can ensure certain invariants are maintained. You cannot duplicate this with just a standard hash.
>and inheritance lets humans do what they love to do - name and categorize things.
You say that like its a bad thing. If humans like to categorize, why shouldn't our programming languages be designed around this tendency?
I've always had the impression that we (at least as programmers) are incredibly bad at categorizing things into hierarchies.
I think class hierarchies (and module hierarchies for that matter) suffer from a similar problem to that of hierarchical file systems, there is often more than one way of organizing the items and it's unclear which way is right. I'd like to see if one could use a tagging mechanism instead; I guess interfaces/mixins/traits could be thought of as tags for classes though.
Namespacing, and modularization in general, are cornerstones of well structured code. OOP gives you nice tools to help with this.
Leave out inheritance, but keep interfaces, and you get better OOP.
Inheritance is a very useful tool, but like many other things, overuse of inheritance is worse than not using it at all.
Most of the qualities that make VB6 VB have nothing to do with inheritance. This is a logical fallacy, where you argue by associating one quality with something looked down upon.
When I see OO code, I mostly think about the bundling of code with the data it operates on, but that is basically a module. So maybe it should be called module-oriented programming?