The Dart mixins

/ * 
Mixins in Chinese means mixed, that is mixed with other functions in the class. 

Dart mixins can be used in multiple inheritance to achieve similar functionality, with keywords 


because mixins conditions of use, with the Dart version has been changed, here talking about the condition of Dart2.x use mixins: 

  1, as mixins class only inherit from Object, the class can not inherit the other 
  two, as can mixins class constructors 
  3, a plurality of class mixins mixins classes 
  . 4, mixins not inherited, nor the interface, but a new property 
* / 

class A {
   String info = "the this IS A" ; 
  void Printa () { 
    Print ( "A" ); 
  } 
} 

class B { 
  void printB () { 
    Print ( "B" ); 
  } 
} 

class C with A, B { 
  
} 

main void () { 
  
  var C = new newC ();  
  c . print (); 
  c . printB ();
  print (c. about); 


}
/ * 
Mixins in Chinese means mixed, that is mixed with other functions in the class. 

You can use mixins in Dart multiple inheritance to achieve a similar function 


as the conditions of use mixins, Dart with version has been changed, here talking about the condition of Dart2.x use mixins: 

  1, as mixins class can only inherit from Object not inherit other classes 
  2, not as mixins class constructors 
  3, a plurality of class mixins mixins classes 
  . 4, mixins not inherited, nor the interface, but a new property 
* / 

class the Person {
   String name ; 
  NUM Age; 
  the Person (the this .name, the this. Age); 
  printInfo () { 
    Print ( '$ ---- $ {} {this.name this.age}' ); 
  } 
  void RUN () { 
    Print ( " the Run the Person " ); 
  } 
} 

class A {
   String info =" the this IS A " ;
  void Printa () { 
    Print ( "A" ); 
  } 
  void RUN () { 
    Print ( "A the Run" ); 
  } 
} 

class B {   
  void printB () { 
    Print ( "B" ); 
  } 
  void RUN () { 
    Print ( "the Run B" ); 
  } 
} 

class C the extends the Person with B, a { // if the same methods a, B who is in the process executed in the back who 
  C ( String name, Age NUM): Super (name , Age); 
  
} 

void main () {   
  var C = new new C ( 'John Doe', 20 is );   
  C .print info ();
  // c.printB (); 
  // print (c.info); 

   c . run (); 


}
/ * 
What mixins instance type? 

Very simple, a subtype of the type of mixins is its superclass. 

* / 



Class A {
   String info = "the this IS A" ; 
  void Printa () { 
    Print ( "A" ); 
  } 
} 

class B { 
  void printB () { 
    Print ( "B" ); 
  } 
} 

class C with A, {B 
  
} 

void main () {   
   var C = new new C ();   
   
  Print (C C IS);     // to true 
  Print (A C IS);     // to true 
  Print (B C IS);    // to true


  // var a=new A();

  // print(a is Object);


}

 

Guess you like

Origin www.cnblogs.com/loaderman/p/11026875.html