Mixin in dart
Flutter is becoming the most popular language now for mobile development. When developers write code, they encounter the keyword 'with'. Now the question arises: what does that keyword mean in Dart programming language, and what is the use of it?
Let's discuss it. Mixin is a kind of inheritance that which promote the reuse of code, With the example of Students class , we can understand it in more detail.
class Students {
void name(){}
void roll(){}
void subjects(){}
}
Now to reuse the code, we can break it into smaller parts with the help of Mixin.
class Students with Name,Roll{
void subjects(){}
}
mixin Name {
void name(){}
}
mixin Roll {
void roll(){}
}
This is how we can reuse code with the help of Mixin.
Why Mixin if we can do the same thing with the help of extends and implements?
extends and implments can use with inheritence but they have some limitations.
To overcome above two implementation , we uses mixin in dart. I hope you understand the basics. I hope that will satisfy your curiosity about, with and implements or extends.