Mixin in dart

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.

  1. extends allow to inherit only one class,
  2. implements allow to implements many interface but you have to define all the method which is already define in the interface.

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.





要查看或添加评论,请登录

Rajendra Verma的更多文章

  • My First AI Model

    My First AI Model

    If you will check the below table, then you will get to know that Y is dependent on X and the relationship is. y = 2x -…

  • Evolution of Neural Network

    Evolution of Neural Network

    This is a very intersecting topic, just like an Netflix webseries. Now a days everyone is talking about AI, but no one…

  • What is Deep Learning?

    What is Deep Learning?

    A subset of machine learning: Deep learning is a branch of machine learning that focuses on using artificial neural…

  • Very Good CLI vs Flutter CLI: A Clear Distinction

    Very Good CLI vs Flutter CLI: A Clear Distinction

    We all know about Flutter cli, that it is known to develop the project and that it works to update and upgrade the…

  • Flutter Internationalization

    Flutter Internationalization

    When you create a mobile app and it hits the international market, you have to internationalize the app which is an…

  • Types of provider in Flutter

    Types of provider in Flutter

    I was working on one of my Flutter projects, and suddenly I thought that it is a good idea to explain the difference…

  • Flutter

    Flutter

    A couple of days ago, I was thinking of learning to flutter because of market requirements. But I find it too easy and…

  • My Experiment with the Matter Protocol

    My Experiment with the Matter Protocol

    Exploring the Future of IoT: An In-Depth Look at the Matter Protocol As a software engineer specializing in IoT…

  • How to filter array of a positive integer and negative integer in kotlin

    How to filter array of a positive integer and negative integer in kotlin

    Interviews are asking a general question nowadays from Kotlin developers so that I like to give its answer fun main(){…

  • Print numbers with using recursion and without using recursion and loop in java.

    Print numbers with using recursion and without using recursion and loop in java.

    I was taking the interview and the thought comes, let's put a question to the interviewee that you have to print…

社区洞察

其他会员也浏览了