Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Yegor Bugayenko
    @yegor256
    Allen says: "You should avoid implementation inheritance whenever possible". this is what bothers me - this "whatever possible" part. does it mean that sometimes we need inheritance?
    SJTsai
    @SJTsai
    I guess there's Liskov's that you can refer to. Don't know if that helps though
    Yegor Bugayenko
    @yegor256
    please, don't say that inheritance is usually bad, we all know that, there are tons of articles about it
    my question: can we just say that inheritance is a mistake in OOP? David West thinks so, by the way
    if it's not a mistake than what is the rule of using it? when it's acceptable and when it's a bad idea?
    Yegor Bugayenko
    @yegor256
    and I'm talking about "implementation inheritance": class Foo extends Bar
    Silas Reinagel
    @SilasReinagel
    A heuristic that I heard from several experience engineers is: One level of inheritance is acceptable, but never more.
    Yegor Bugayenko
    @yegor256
    @TheoConfidor that sounds like a rule, thanks
    Silas Reinagel
    @SilasReinagel
    Personally, I only use inheritance for abstract classes, at this point. Template Method Pattern is very useful.
    SJTsai
    @SJTsai
    Like you Yegor, I've found that anything done with inheritance can be done with composition
    So I'm not really sure
    It'd be nice to understand what Alan Kay is trying to say in the link though
    Yegor Bugayenko
    @yegor256
    David West said in the interview (to be published soon) that inheritance was invented in order to re-use functionality and it's a terrible mistake
    Foo extends Bar is a what doesn't exist in real world
    and I can't say I agree with that
    in real world a Dog definitely inherits many qualities from a Wolf
    and a Chair definitely inherits a lot from a Furniture Element
    JP
    @nqafield
    @yegor256 Do you see "qualities" as anything like "behaviour"? Could you say a dog does some of the same things as a wolf?
    Yegor Bugayenko
    @yegor256
    I guess..
    but David West says that the idea of a "class" is also wrong. it must not exist in OOP
    if we remove classes, we definitely won't have inheritance
    but then I don't know how everything will work :)
    JP
    @nqafield
    Are interfaces classes?
    Yegor Bugayenko
    @yegor256
    no, interfaces is a separate thing
    David said that classes were invented just to get rid of copy-paste problem
    but they should not exist in OOP, as concepts
    maybe that's why inheritance is a "bad" idea... I'm just thinking out loud
    SJTsai
    @SJTsai
    They're types, but you have to realize that an interface is simply a set of messages that can be sent
    Yegor Bugayenko
    @yegor256
    yeah, interfaces are types, I agree
    we can say that "Lucy" is a an object of type "Dog"
    type "Dog" requires everybody to be able to "walk()"
    "Lucy" walks this way: print "I am walking"
    so, there is no place for a class in this story so far
    we just say:
    Lucy = new {
      walk() { print "I am walking"; }
    }
    then, we want Max to be another dog, but a smarter one
    and we say:
    Max = new {
      walk() { print "I am walking"; }
      jump() { print "see, I can jump!"; }
    }
    even though there are obvious commonalities between Max's and Lucy's behavior, would be weird to say that Max "inherits" Lucy, right?
    Max is not a child of Lucy
    Yegor Bugayenko
    @yegor256
    my point is that "inheritance" in Java/C++ is a very technical concept, not really conceptual
    Max is not Lucy
    Silas Reinagel
    @SilasReinagel
    yes. it is a conceptual metaconcept
    we use it to categorize the world
    but the world does not exist that way
    Yegor Bugayenko
    @yegor256
    Max has nothing to do with Lucy
    JP
    @nqafield
    Yep @yegor256 . A "mechanism".
    Yegor Bugayenko
    @yegor256
    even though they "walk()" very similar
    Silas Reinagel
    @SilasReinagel
    More importantly, "Dog" is a broad concept, which becomes increasingly blurry at the edges
    JP
    @nqafield
    Similar traits? ;)