The intersection of technology and leadership

Apparently I dislike OO

Wow. I am stunned. Apparently I don’t like Object Oriented programming because I think inheritance is a poor man’s method for reuse. Hmm…

12 Comments

  1. gaboto

    Inheritance is not object oriented programming man. Object oriented programming is programming with a simple metaphor: objects collaborating each other by sending messages.

  2. csharptest

    huh? ok, you have my curiosity up… care to explain?

  3. Robert

    Inheritance of type is a key aspect of polymorphism in type-based OO (of course, you can have typeless OO as well).

    Inheritance of behaviour is a syntactic shortcut for composition by delegation where there is a “parent” of the same type to delegate to.

    Mixins are another syntactic shortcut for composition by delegation.

    Avoiding inheritance where it makes sense is silly. Cramming it in where it doesn’t is sillier.

  4. gaboto

    Inheritance is neither good nor bad. It is just a mechanism to share behavior between objects. It could be great if we could have different mechanisms to do so…
    Take a look to the self language and environment

  5. toni

    What?
    Who said that to you?
    Do I have to mobilize the family?

    🙂

  6. Patrick

    >> Gaboto
    Totally agree with you. I find that inheritance is the least useful (but unfortunately for many others, the most common) way of sharing behaviour between objects. I find it not only ties objects to each others’ lifecycles as well as coupling them far too close for my liking.

    >> Csharptest
    I find developers who haven’t done much TDD or much Dependency Injection automatically reach towards extending an object, simply to share behaviour (without really thinking about the is-a vs the has-a relationship). I used to be one of them. These days, I find that reuse via composition is a much more elegant way of sharing behaviour.

    >> Robert
    I disagree that inheritance of behaviour is syntactic shortcut. Two objects of the same hierarchy are bound much closer together than just through code use. Their entire object lifecycle is entwined which makes it difficult to separate them at a later stage. I agree that avoiding inheritance where it makes sense is silly. I just find it doesn’t make sense a lot of the time 🙂

  7. Dale

    At uni (ahhh…. the good old days) I had 2 modules explicitly on OO. Begining OO and Advanced OO. 90% of Advanced OO was related to inheritance. Vague memories of drawing out a sequnce diagram for the destruction of a crazy c++ inheritance heirarchy.

    I weep for our industry.

  8. Patrick S

    You should not inherit for reusing code, but because there is an inhertiance relationship. Sounds like writing things twice more often, but no, that actually works.

    If you feel like having to inherit just to reuse an implementation, 95% of the time your model is simply wrong.

  9. csharptest

    Patrick,

    Agreed that ‘Object Oriented’ development does not necessitate the use of inheritance nor is inheritance always the best approach. There are cases when a descent OO design includes inheritance/derivations, just as there are valid uses of multiple inheritance. These can tend to be misused and abused by less tenured developers. I have to agree with gaboto:
    “Inheritance is neither good nor bad. It is just a mechanism to share behavior between objects.”

    I rate it akin to giving a two-year-old a hammer. He’s far more likely to hurt himself and others than to accomplish something useful. Still we all have to learn and grow and we all started life being dangerous with both code and hammers alike.

  10. consumer

    I felt that too, but then I understood that inheritance is just a *tool*, which works poorly in most cases, but in some cases it may work extremely well. So, use the right tool for the job. Cheers.

  11. matt mcknight

    In many cases, I use inheritance (in Java) to avoid creating too many interfaces. I use it far less in Ruby, because “quack quack quack” seems to work pretty well.

  12. Ben

    I’m an OO hater too. The best design pattern for reuse – copy n paste.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 patkua@work

Theme by Anders NorenUp ↑