← Back to context

Comment by ChrisMarshallNY

5 days ago

I always considered an "object" to be data with identity and state.

All the other stuff, like polymorphism, encapsulation, etc., I consider "addons."

I think the biggest mistake was to teach inheritance as a main feature of OOP. I have done some stuff with inheritance but it was very specialized and it would have been fine without inheritance.

  • Back in the day, I used to do OOP with C.

    It was a common pattern, back then. We’d pass around structs, and have a small library of functions that accessed/modified the data in these structs.

    If you wanted, you could add function pointers to the structs. You could add “polymorphism,” by overwriting these pointers, but it was messy.

    That said, inheritance can be very useful, in some cases, like improving DRY. I don’t like to take absolute stances, so much, these days.

    • Reminds me of cube the engine of sauberbraten2 - who uses a C/C++ hybrid with complex inheritance to inherit methods - like everything is a starts as an object. And so on and so forth.. turning inheritance into basically a mapped out set theory with the final class being the outermost part of a set holding the abilities of all inner sets. https://github.com/embeddedc/sauerbraten/tree/master/src

      Its not very intuitive used that way.

  • But OOP needs something to distinguish it from the rest, otherwise it's just P.

    Do people honestly think other languages don't do whatever definition OOP has today? Encapsulation & polymorphism? Message-passing & late-binding?

    Inheritance is the one thing that the other languages took a look at and said 'nope' to.

    (Also, the OOP texts say to prefer composition anyway)

    • IME with this sort of thread there is a huge correlation between praising OOP and believing that encapsulation is an identifying feature of OOP. Also polymorphism to a much lesser extent, but the other two almost none.

      It is very difficult to tell whether this is a definitional problem - people believe any kind of encapsulation is OOP - or if some people can't wrap their heads around how to do encapsulation without message passing and the rest.