Incase it doesn’t show up:

  • void_star@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I have not heard this consensus. Definitely inheritance where the base class holds data or multiple inheritance, but I thought abstract was still ok. Why is it bad?

    • magic_lobster_party@fedia.io
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      In 99% of the cases, inheritance can easily be replaced with composition and/or interfaces. Abstract classes tend to cause hard dependencies that are tough to work with.

      I’m not sure why you would use abstract classes without data. Just use interfaces.

      • jaybone@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        Say List is an interface.

        You have implementations like ArrayList and LinkedList.

        Many of those method implementations will differ. But some will be identical. The identical ones go in the abstract base class, so you can share method implementation inheritance without duplicating code.

        That’s why.

        • magic_lobster_party@fedia.io
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          If the lists have shared components then that can be solved with composition. It’s semantically the same as using abstract classes, but with the difference that this code dependency doesn’t need to be exposed to the outside. This makes the dependency more loosely coupled.