jakt icon indicating copy to clipboard operation
jakt copied to clipboard

Inheritance

Open awesomekling opened this issue 2 years ago • 5 comments

Classes and structs should be allowed to inherit from other classes and structs respectively.

class Animal {
}

class CatDog: Animal {
}

struct Sport {
}

struct Football: Sport {
}

Note that a struct can't inherit from a class and vice versa, as that would break the reference counting ownership model.

awesomekling avatar May 19 '22 15:05 awesomekling

What should syntax for multiple inheritance look like?

linusg avatar May 19 '22 16:05 linusg

What should syntax for multiple inheritance look like?

Good question! I would like to explore if we can avoid multiple inheritance and instead express interfaces/protocols/traits using a separate mechanism. :^)

awesomekling avatar May 19 '22 16:05 awesomekling

I know it's very very early but I hope to see soon some proper light RFCs so some thought goes into these and a public roadmap. Very interested how this will evolve.

iKlsR avatar May 20 '22 00:05 iKlsR

Great input!

nasloj avatar May 23 '22 06:05 nasloj

Dart uses mixins, a concept which lets you add features to a class without using multiple inheritance like explained in this article.

If you are allowing inheritance, please consider adding super calls in the constructor and avoid having to call the super constructor explicitly, as was just announced in Dart 2.17 :)

erf avatar May 23 '22 23:05 erf