3 ms·
When writing a program, you usually don't model the Platonic ideals that make up the universe, with perfect encapsulation. You model aspects of the world releva
by seregine 17y ago
When writing a program, you usually don't model the Platonic ideals that make up the universe, with perfect encapsulation. You model aspects of the world relevant to the problem you're solving. You give them shorthand names that make sense in the context of the program, not in the infinite real universe. A Bike class in an ecommerce app means something different than a Bike class in a bike-racing video game. Reusing the ecommerce class in the game context is a silly requirement.
Instead of "hiding", think of encapsulation as "organizing". You can organize verbs, most of the time, by the parts of program state they deal with. There are multiple reasonable ways to do it. That's what makes object modeling a more flexible tool than you give it credit for.
- gdp 17y ago> Instead of "hiding", think of encapsulation as "organizing". You can organize verbs, most of the time, by the parts of program state they deal with. Isn't that reinforcing the point that the main way that OOP is useful is for name-space control, which is achievable in many non-OO ways?
- apotheon 17y agoI think that's the point -- encapsulation is achievable in many non-OO ways, and encapsulation is basically just a subset of namespace management. In other words, encapsulation itself isn't necessarily bad, so griping about encapsulation doesn't seem like a very productive way to "prove" that OOP is "bad".
- dasil003 17y agoHm, I'm not sure about that. The thrust of the argument seems to be that object orientation conflates state and behavior far beyond the point that it is useful--that things end up getting shoe-horned into objects where it doesn't make sense just to satisfy the paradigm. I think there's definitely something there even if the rant is a little over the top. In my opinion OOP took off because it's such a natural fit for GUI programming and then everyone just started thinking that way. It's natural to think about data types and the functionality that goes along with them, but I don't think you need to go nearly so far down the path that recent languages have taken in order to satisfy that association.
- seregine 17y agoSure, it's just another tool, but OOP is not Java. The original post said "objects are a bad way of modeling the universe."
- dasil003 17y agoMy comment is not specifically about Java. I really think there is a limit to the usefulness of fusing all data to the code that operates on it. I'm not religious about it or anything, I think it's just something that bears consideration in today's software ecosystem.