When writing object oriented code, a pretty useful technique is delegation–letting one object figure things out by sending messages to another object.

  • Solemarc@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    12 days ago

    First of all, I don’t know what language this example is written in, but am I crazy for thinking that the bad imperative example is shorter and easier to read then the delegation?

    I would go a step further and say you don’t need a VideoService class, just make that a function

    • Kache@lemmy.zip
      link
      fedilink
      arrow-up
      1
      ·
      12 days ago

      It’s Ruby. And yes, it could be simpler as a plain, pure function. There is nothing that warrants having the temporary objects, no tricky long-lived state, no leased/shared resource, etc