▲ 102 ▼ The Tragic Death of Inheritance (avivcarmi.com) submitted 3 years ago by snaggen@programming.dev to c/programming@programming.dev 52 comments fedilink hide all child comments
[–] mrsgreenpotato@discuss.tchncs.de 1 point 3 years ago (1 child) What's a good alternative to inheritance in your Animals example? permalink fedilink source parent hideshow 2 child comments replies: [–] snaggen@programming.dev [S] 2 points 3 years ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] mrsgreenpotato@discuss.tchncs.de 1 point 3 years ago (1 child) Thanks for the explanation! I haven't worked with Rust before, would these traits be an equivalent of C# interfaces? permalink fedilink source parent hideshow 2 child comments replies: [–] snaggen@programming.dev [S] 2 points 3 years ago Traits are similar to an interface, but with some differences. Here is a comparison with Java interfaces https://stackoverflow.com/a/69485860 permalink fedilink source parent
[–] snaggen@programming.dev [S] 2 points 3 years ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] mrsgreenpotato@discuss.tchncs.de 1 point 3 years ago (1 child) Thanks for the explanation! I haven't worked with Rust before, would these traits be an equivalent of C# interfaces? permalink fedilink source parent hideshow 2 child comments replies: [–] snaggen@programming.dev [S] 2 points 3 years ago Traits are similar to an interface, but with some differences. Here is a comparison with Java interfaces https://stackoverflow.com/a/69485860 permalink fedilink source parent
[–] mrsgreenpotato@discuss.tchncs.de 1 point 3 years ago (1 child) Thanks for the explanation! I haven't worked with Rust before, would these traits be an equivalent of C# interfaces? permalink fedilink source parent hideshow 2 child comments replies: [–] snaggen@programming.dev [S] 2 points 3 years ago Traits are similar to an interface, but with some differences. Here is a comparison with Java interfaces https://stackoverflow.com/a/69485860 permalink fedilink source parent
[–] snaggen@programming.dev [S] 2 points 3 years ago Traits are similar to an interface, but with some differences. Here is a comparison with Java interfaces https://stackoverflow.com/a/69485860 permalink fedilink source parent