Incase it doesn’t show up:

  • magic_lobster_party@fedia.io
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    17 days ago

    So things like abstract classes are mostly absent from my codebase.

    I believe the consensus nowadays is that abstract classes should be avoided like the plague even in languages like Java and C#.

    • void_star@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      17 days 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
        ·
        17 days 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.

        • Zangoose@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          17 days ago

          The way I was taught was that you usually start off with only an interface and then implementing classes, and then once you have multiple similar implementations it could then make sense to move the common logic into an abstract class that doesn’t get exposed outside of the package

          • magic_lobster_party@fedia.io
            link
            fedilink
            arrow-up
            1
            ·
            17 days ago

            I usually break it out using composition if that’s ever needed. Either by wrapping around all the implementations, or as a separate component that is injected into each implementation.

          • magic_lobster_party@fedia.io
            link
            fedilink
            arrow-up
            0
            ·
            17 days ago

            Ask Bjarne to add interfaces enough many times until he gives in.

            On a more serious note, I’m not exactly sure what the best C++ practice is. I guess you just have to live with abstract classes if you really want interfaces.

        • jaybone@lemmy.world
          link
          fedilink
          arrow-up
          0
          arrow-down
          1
          ·
          17 days 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.