Intermediate Dart
  • Welcome to the Course
  • Course Overview
  • Resources
  • Dart Fundamentals-2
    • Section Overview
    • Basic Concepts
      • Class
      • Object/Instance
      • Instance /Field Variables
      • Methods
      • "this" keyword-1
    • Constructor
      • Default Constructor
      • Parameterised Constructor
        • Basic Parameterised Constructor & "this" keyword -2
        • Parameterised Constructor with Syntactic sugar
        • Optional Arguments in Parameterised Constructor
      • Named Constructor
    • Getters & Setters and Encapsulation
      • Access Modifiers and _ symbol
      • Implicit / Default Getters & Setters
      • Custom Getters and Setters
      • Encapsulation
    • Inheritance
      • Inheritance, Types of Inheritance , Terminology
      • Method Overriding
      • @override annotation
      • super Keyword -1
      • super Keyword -2
    • Polymorphism
    • Static Variables and Methods
    • Abstract Class and Abstract Methods
    • Interface
    • Miscellaneous concepts
      • Untitled
      • Object Class
      • Mixin
      • Immutable Instances
      • Cascade notation
  • Dart Fundamentals -3
    • Section Overview
    • Asynchronous Programming
      • Basic Concept of Asynchronous programming
      • async , await , then
      • Exception Handling in asynchronous code
    • Functional Programming
      • Anonymous functions
      • High Level Iterators
    • Advanced Asynchronous Programming
      • Isolates
      • Streams
      • Generators
      • Microtask and Zones
    • Method & Constructor Overloading
Powered by GitBook
On this page
  • Introduction to mixin
  • Mixin in Inheritance hierarchy
  • "on" Keyword

Was this helpful?

  1. Dart Fundamentals-2
  2. Miscellaneous concepts

Mixin

PreviousObject ClassNextImmutable Instances

Last updated 4 years ago

Was this helpful?

Mixin specifications are evolving in Dart . Keep up to date with the specification and documentation

Introduction to mixin

void main() {
  // Mixins
​
//   var manager1 = Manager();
​
//   manager1.manageproject();
​
//   manager1.work();
​
  var ceo1 = CEO();
​
  ceo1.manageproject();
  ceo1.work();
  ceo1.recruit();
}
​
class Employee {
  void work() {
    print("Work");
  }
}
​
class HR extends Employee {
  void recruit() {
    print("Recruit Employee");
  }
}
​
class Manager extends Employee with CanManageProject {}
​
class CEO extends HR with CanManageProject {}
​
mixin CanManageProject {
  void manageproject() {
    print("manage project");
  }
}
​

Mixin in Inheritance hierarchy

void main() {
  // Mixins

//   var manager1 = Manager();

//   manager1.manageproject();

//   manager1.work();

  var ceo1 = CEO();

  ceo1.startproject();
}

class Employee {
  void work() {
    print("Work");
  }
}

class HR extends Employee {
  void recruit() {
    print("Recruit Employee");
  }

  void keeplog() {
    print("keep log for recurit ");
  }
}

class Manager extends Employee with CanManageProject {}

class CEO extends HR with ExecutiveDecision, CanManageProject {
  void startproject() {
    manageproject();

    keeplog();
  }
}

mixin CanManageProject {
  void manageproject() {
    print("manage project");
  }

  void keeplog() {
    print("Log for managing project");
  }
}

mixin ExecutiveDecision {
  void decision() {
    print("Executive Decision");
  }

  void keeplog() {
    print("Log for Executive Decision");
  }
}

"on" Keyword

void main() {
  var ceo1 = CEO();

  ceo1.startproject();
}

class Employee {
  void work() {
    print("Work");
  }
}

class HR extends Employee {
  void recruit() {
    print("Recruit Employee");
  }

  void keeplog() {
    print("keep log for recurit ");
  }
}

class Manager extends Employee with CanManageProject {}

class CEO extends HR with ExecutiveDecision, CanManageProject {
  void startproject() {
    manageproject();

    keeplog();
  }
}

class CTO extends HR with ExecutiveDecision, CanManageProject {}

mixin CanManageProject {
  void manageproject() {
    print("manage project");
  }

  void keeplog() {
    print("Log for managing project");
  }
}

mixin ExecutiveDecision on HR {
  void decision() {
    print("Executive Decision");
  }

  void keeplog() {
    print("Log for Executive Decision");
  }
}

language/feature-specification.md at master · dart-lang/languageGitHub
Logo