The Bard's Lemmy
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@snaggen@programming.dev to Programming@programming.devEnglish • 2 years ago

The Tragic Death of Inheritance

avivcarmi.com

message-square
38
fedilink
  • cross-posted to:
  • rust@programming.dev
59
external-link

The Tragic Death of Inheritance

avivcarmi.com

@snaggen@programming.dev to Programming@programming.devEnglish • 2 years ago
message-square
38
fedilink
  • cross-posted to:
  • rust@programming.dev
This is a story about how I gradually fell in love with composition
alert-triangle
You must log in or register to comment.
  • @mrsgreenpotato@discuss.tchncs.de
    link
    fedilink
    English
    1•2 years ago

    What’s a good alternative to inheritance in your Animals example?

    • @snaggen@programming.devOP
      link
      fedilink
      2•2 years ago

      If you look at Rust for example, then you specify the Traits instead. So, you could define a trait that defines the properties for birth, another to define if the animal have a beak, and another one to define the number and type of legs. The each animal implement these traits, which then properly can define a duck, cat and a platypus.

      • @mrsgreenpotato@discuss.tchncs.de
        link
        fedilink
        English
        1•2 years ago

        Thanks for the explanation! I haven’t worked with Rust before, would these traits be an equivalent of C# interfaces?

        • @snaggen@programming.devOP
          link
          fedilink
          2•2 years ago

          Traits are similar to an interface, but with some differences. Here is a comparison with Java interfaces https://stackoverflow.com/a/69485860

Programming@programming.dev

!programming@programming.dev
Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programming@programming.dev

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



  • 8 users / day
  • 70 users / week
  • 281 users / month
  • 1.05K users / 6 months
  • 2 subscribers
  • 1.75K Posts
  • 15.7K Comments
  • Modlog
  • mods:
  • snowe
  • Ategon
  • BE: 0.18.2
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org