# \[Share\] Interesting behaviour for mixin

**URL:** <https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803>\
**Category:** Dart Apprentice: Beyond the Basics\
**Created:** [February 10, 2023, 3:35pm UTC](https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803 "2023-02-10T15:35:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellery](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ellery/32/110937_2.png) [@ellery](https://forums.kodeco.com/u/ellery)\
**Post date:** [February 10, 2023, 3:35pm UTC](https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803/1 "2023-02-10T15:35:18Z")

</div>

Hi I would like to share an interesting behaviour below:  
See the code:

```dart
mixin EggLayer {
  void layEggs() {
    print('Plop plop');
  }
}
  
mixin Flyer {
  void fly() {
    print('Swoosh swoosh');
  }
}
  
abstract class Bird {
  void fly() {
    print("parent parent");
  }
  void layEggs();
}

class Robin extends Bird with EggLayer, Flyer {
  @override
  void fly() {
    super.fly();
    print("child child");
  }
}

```

In `main`:

```dart
final robin = Robin();
robin.fly();
robin.layEggs();
// output below:
// Swoosh swoosh
// child child
// Plop plop

```

Explanation:

- The `fly` method in mixin has shadowed over the `fly` method in `Robin` class.

---

<div class="post-metadata">

**Author:** ![suragch](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/suragch/32/109020_2.png) [@suragch](https://forums.kodeco.com/u/suragch)\
**Post date:** [February 13, 2023, 5:42am UTC](https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803/2 "2023-02-13T05:42:31Z")

</div>

Let me filter out the egg laying code since it doesn’t apply to the interesting behavior:

```auto
void main() {
  final robin = Robin();
  robin.fly();
  // Swoosh swoosh
  // child child
}

mixin Flyer {
  void fly() {
    print('Swoosh swoosh');
  }
}

abstract class Bird {
  void fly() {
    print("parent parent");
  }
}

class Robin extends Bird with Flyer {
  @override
  void fly() {
    super.fly();
    print("child child");
  }
}

```

You’ve got three separate implementations of `fly`. Normally `super.fly()` would print “parent parent”, but the mixin overrides the parent method. However, the mixin doesn’t override the child method. That is interesting.

I like how you’re exploring the edges of the language. Good job.

---

<div class="post-metadata">

**Author:** ![ellery](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ellery/32/110937_2.png) [@ellery](https://forums.kodeco.com/u/ellery)\
**Post date:** [February 13, 2023, 2:30pm UTC](https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803/3 "2023-02-13T14:30:14Z")

</div>

@suragch thank you for your appreciation. I don’t intent to test it like that at the first reading. But when I try to write the notes for mixin section, the idea of using `super.fly()` suddenly pop up in my head. So, that’s the origin of coming up this idea.

---

<div class="post-metadata">

**Author:** ![kpere](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kpere/32/109586_2.png) [@kpere](https://forums.kodeco.com/u/kpere)\
**Post date:** [June 19, 2023, 10:15am UTC](https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803/4 "2023-06-19T10:15:38Z")

</div>

Dear @ellery

We hope that the response provided by @suragch was helpful in addressing your concerns.

If you have further questions or need additional assistance, please don’t hesitate to ask. Our community is here to support you!

---

<div class="post-metadata">

**Author:** ![kpere](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kpere/32/109586_2.png) [@kpere](https://forums.kodeco.com/u/kpere)\
**Post date:** [June 26, 2023, 12:20pm UTC](https://forums.kodeco.com/t/share-interesting-behaviour-for-mixin/183803/5 "2023-06-26T12:20:29Z")

</div>


