Oh boy, multiple inheritance! Already "achievable...
# language-proposals
h
Oh boy, multiple inheritance! Already "achievable" like so:
Copy code
interface Bar {
    val bar: Int
    companion object {
        operator fun invoke(bar: Int) = object : Bar {
            override val bar = bar
        }
    }
}

interface Baz { 
    ...same as how Bar is implemented 
}

class Foo(bar: Int, baz: Int): Bar by Bar(bar), Baz by Baz(baz)
but wouldn't it be nice to just:
Copy code
class Foo(bar: Int, baz: Int): Bar(bar), Baz(baz)
5
r
Is this a proposal or a question?
All discussion in this channel should begin with a use-case or proposal instead of a question.
If you're proposing multiple inheritance, please word it as such. If you're simply asking why it's not allowed, you should probably try a different channel.
h
Yeah, I already posted it to general with the advice to move it here, so I'll just reword it as a proposal...
👍 1
g
I didn’t get it. It’s not a real inheritance, because you cannot extend 2 classes, only interfaces
☝️ 1
the biggest problem that in case of classes you actually can have state, but not in interface
In you example above it’s just a creation of default instance
j
In Dart multiple inheritence is possible via mixins A extends B with C, D, E
Although interfaces since JDK8 already makes multiple inheritance almost as nice.
h
Yeah, I'm not sure the classic wisdom of "never allow for multiple inheritance" holds today. I don't see what's wrong with it.
1
g
Multiple inheritance is like all problems of inheritance but multiplied
r
Hmm, aptly named indeed
j
Composition in most cases is a better choice than Inheritance, but there are cases where inheritance makes more sense. Mixins can technically already be achieved via
class A : B(), C, D, E
where B is a class / abstract class and C-E are interfaces
g
Interface is not really inheritance, you do not inherit any behavior or state, you just declare that your class is implementation of some contract
And it's the biggest difference comparing to what you have in Dart, where you actually can inherit some state
Also funny that mixin example used for this article is really bad, you would never want such code in a real project
1. It's against inversion of control 2. This particular code can be easily replaced with Singleton, also against IoC but at least explicit and doesn't require any inheritance