Krupal Shah Krupal Shah - 2 months ago 5x
Dart Question

Understanding 'implements' and 'with' in Dart

I am just reading Dart language specification and exploring a new interesting language. As Dart language specification says: Dart has

implicit interfaces
. Which means every
is an
too. So, If I want to implement some behavior of another class,
clause is the only I need.

Also, Dart supports
. So that we can take implementation of methods from another class using

So, given that if an abstract class A defines method a() like :

abstract class A {
void a();

and another two concrete class B defines method a() but does not implements class A like:

class B {
void a() {
print("I am class B");

and class C implements class A with Mixin B like :

class C extends Object with B implements A {

Here, I have few questions about it. If a class implements the interface and also use mixin that has method implementation with same method name; doesn't it would make
cycling inheritance
What will be the behaviour of
class C
? Does it need to implement
or it will be implicitly implemented by
mixin B

I am just learning Dart and concepts like mixins are very unfamiliar to me. Can anyone help me understanding by answering my questions?


Mixins are a kind of limited multiple inheritance. With C with B, C inherits an implementation of void a(). Adding implements A doesn't need anything more to be done, because C already fulfills the contract it claims to fulfill by implements A, because of B.