Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Add Mixins

This video was last updated on Jun 28 2022

Add new behavior to your classes by this useful language feature called Mixins.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

You’ve learned how to create interfaces. It’s a great way for different classes to have similar behavior. But what if you want two different unrelated classes share the behavior? Well, for that, you use Mixins. A mixin is a bit of code that other code can incorporate.

class Calculator {}
final calculator = Calculator();
mixin Adder {

}
void sum(num a, num b) {
    print('The sum is ${a + b}.');
}
class Calculator with Adder {}
calculator.sum(4, 6);

Reviews

Comments