Cambo Freelance
ទំព័រដើមសេវាកម្មអត្ថបទការបង្រៀនក្រុមវគ្គបណ្តុះបណ្តាលទំនាក់ទំនង
Cambo Freelance

Professional freelance team from Cambodia delivering technology-driven solutions with cultural insight and modern expertise.

ផ្ញើសាររបស់អ្នក

ត្រៀមចាប់ផ្តើមគម្រោងរបស់អ្នក? ទំនាក់ទំនងក្រុមរបស់យើង។

ទំនាក់ទំនង

សេវាកម្ម

  • Web & Mobile Development Services
  • Graphic Design & Branding Services

តំណភ្ជាប់មានប្រយោជន៍

  • ទំព័រដើម
  • សេវាកម្ម
  • ការសិក្សា
  • អំពីយើង
  • ទំនាក់ទំនង
  • តម្លៃ

© 2026 Cambo Freelance. រក្សាសិទ្ធិទាំងអស់។

TelegramFacebookLinkedInEmail
HomeTutorialsDartInterfaces in Dart
🎯Dart Tutorials

97 lessons

Beginner(35)0Complete Dart Tutorial Series — Course Index1Introduction to Dart2Installing Dart SDK3Setting Up VS Code for Dart4DartPad Online Editor5Hello World in Dart6Dart Syntax7Comments in Dart8Variables in Dart9Data Types in Dart10Strings in Dart11Numbers in Dart12Booleans in Dart13Type Conversion in Dart14Constants in Dart: final and const15User Input in Dart16Arithmetic Operators in Dart17Assignment Operators in Dart18Comparison Operators in Dart19Logical Operators in Dart20Null-Aware Operators in Dart21If Statement in Dart22If Else in Dart23Else If in Dart25Switch Statement in Dart26Ternary Operator in Dart27For Loop in Dart28While Loop in Dart29Do While Loop in Dart30Break and Continue in Dart32Nested Loops in Dart33Functions in Dart35Optional Parameters in Dart37Arrow Functions in Dart38Recursive Functions in Dart
Intermediate(34)39Lists in Dart40Sets in Dart41Maps in Dart42Collection Operations in Dart
Advanced(28)73Futures in Dart74Async and Await in Dart75Streams in Dart76
🎯

Dart Tutorials

Lesson 55 of 97

All lessons
Beginner (35)0Complete Dart Tutorial Series — Course Index1Introduction to Dart
43
Spread Operator and Collection Literals in Dart
44Collection If in Dart
45Collection For in Dart
46Null Safety in Dart
47Nullable Variables in Dart
48Null Assertion Operator in Dart
49Late Keyword in Dart
50Required Keyword in Dart
51Classes and Objects in Dart
52Constructors in Dart
53Getters and Setters in Dart
54Static Members in Dart
55Interfaces in Dart
56Polymorphism in Dart
57Inheritance in Dart
58Method Overriding in Dart
59Abstract Classes in Dart
60Abstract Classes vs Interfaces in Dart
61Mixins in Dart
62Extension Methods in Dart
63Exception Handling in Dart
64Try-Catch in Dart
65Finally Block in Dart
66Custom Exceptions in Dart
67Generics in Dart
68Typedef in Dart
69Enums in Dart
70Records in Dart
71Pattern Matching in Dart
72Cascade Notation in Dart
Stream Controllers in Dart
77Isolates in Dart
78File Operations in Dart
80JSON Parsing in Dart
82HTTP Requests in Dart
83REST API Client in Dart
84Dart Packages and pub.dev
85Testing in Dart
86Dart CLI Applications
87Dart Code Style and Best Practices
88Server-side Dart with Shelf
89Introduction to Flutter
90Flutter Widgets and Layouts
91Flutter State Management
92Flutter Navigation and Routing
93Project: Calculator in Dart
94Project: Temperature Converter in Dart
95Project: Age Calculator in Dart
96Project: Todo CLI App in Dart
97Project: Student Management System in Dart
98Project: Expense Tracker in Dart
100Project: Banking System in Dart
101Project: Inventory Management System in Dart
102Project: Contact Manager in Dart
103Project: Mini REST API Backend in Dart
2
Installing Dart SDK
3Setting Up VS Code for Dart
4DartPad Online Editor
5Hello World in Dart
6Dart Syntax
7Comments in Dart
8Variables in Dart
9Data Types in Dart
10Strings in Dart
11Numbers in Dart
12Booleans in Dart
13Type Conversion in Dart
14Constants in Dart: final and const
15User Input in Dart
16Arithmetic Operators in Dart
17Assignment Operators in Dart
18Comparison Operators in Dart
19Logical Operators in Dart
20Null-Aware Operators in Dart
21If Statement in Dart
22If Else in Dart
23Else If in Dart
25Switch Statement in Dart
26Ternary Operator in Dart
27For Loop in Dart
28While Loop in Dart
29Do While Loop in Dart
30Break and Continue in Dart
32Nested Loops in Dart
33Functions in Dart
35Optional Parameters in Dart
37Arrow Functions in Dart
38Recursive Functions in Dart
Intermediate (34)39Lists in Dart40Sets in Dart41Maps in Dart42Collection Operations in Dart43Spread Operator and Collection Literals in Dart44Collection If in Dart45Collection For in Dart46Null Safety in Dart47Nullable Variables in Dart48Null Assertion Operator in Dart49Late Keyword in Dart50Required Keyword in Dart51Classes and Objects in Dart52Constructors in Dart53Getters and Setters in Dart54Static Members in Dart55Interfaces in Dart56Polymorphism in Dart57Inheritance in Dart58Method Overriding in Dart59Abstract Classes in Dart60Abstract Classes vs Interfaces in Dart61Mixins in Dart62Extension Methods in Dart63Exception Handling in Dart64Try-Catch in Dart65Finally Block in Dart66Custom Exceptions in Dart67Generics in Dart68Typedef in Dart69Enums in Dart70Records in Dart71Pattern Matching in Dart72Cascade Notation in Dart
Advanced (28)73Futures in Dart74Async and Await in Dart75Streams in Dart76Stream Controllers in Dart77Isolates in Dart78File Operations in Dart80JSON Parsing in Dart82HTTP Requests in Dart83REST API Client in Dart84Dart Packages and pub.dev85Testing in Dart86Dart CLI Applications87Dart Code Style and Best Practices88Server-side Dart with Shelf89Introduction to Flutter90Flutter Widgets and Layouts91Flutter State Management92Flutter Navigation and Routing93Project: Calculator in Dart94Project: Temperature Converter in Dart95Project: Age Calculator in Dart96Project: Todo CLI App in Dart97Project: Student Management System in Dart98Project: Expense Tracker in Dart100Project: Banking System in Dart101Project: Inventory Management System in Dart102Project: Contact Manager in Dart103Project: Mini REST API Backend in Dart
🎯DartIntermediateLesson 55 of 97Dart TeamJune 19, 2026

Interfaces in Dart

Learn Dart interfaces — implicit interfaces, the implements keyword, implementing multiple interfaces, abstract classes as interface definitions, and the Repository pattern.


Table of Contents

  1. What are Interfaces?
  2. Implicit Interfaces
  3. implements Keyword
  4. Implementing Multiple Interfaces
  5. Abstract Classes as Interfaces
  6. Full Example
  7. Exercise
  8. Quiz
  9. Summary

What are Interfaces?

An interface defines a contract — a set of methods and properties that a class promises to implement. Unlike inheritance (extends), implementing an interface does not share any code. The implementing class must provide its own implementation of every member. Dart has no dedicated interface keyword — every class implicitly defines an interface.

Implicit Interfaces

In Dart, every class automatically has an implicit interface. Any other class can implement it using implements. When you implement a class, you must provide your own implementation of ALL public members — you get no inherited code:

class Animal {
  String name;
  Animal(this.name);

  void breathe() => print(''$name breathes'');
  void eat() => print(''$name eats'');
}

// Implements Animal''s interface — must define ALL methods
class Robot implements Animal {
  @override
  String name;  // must declare all fields too

  Robot(this.name);

  @override
  void breathe() => print(''$name uses power cells'');

  @override
  void eat() => print(''$name recharges'');
}

implements Keyword

abstract class Printable {
  void print();
}

abstract class Saveable {
  Future<bool> save(String path);
}

abstract class Shareable {
  void share(String recipient);
}

class Document implements Printable, Saveable, Shareable {
  String content;
  Document(this.content);

  @override
  void print() => dart_core.print(''Printing: $content'');

  @override
  Future<bool> save(String path) async {
    dart_core.print(''Saving to $path'');
    return true;
  }

  @override
  void share(String recipient) =>
    dart_core.print(''Sharing with $recipient'');
}

Implementing Multiple Interfaces

A class can implement multiple interfaces simultaneously — this is one of the key advantages of interfaces over inheritance:

abstract class Flyable {
  void fly();
  double get maxAltitude;
}

abstract class Swimmable {
  void swim();
  double get maxDepth;
}

abstract class Runnable {
  void run();
  double get maxSpeed;
}

// Duck implements all three
class Duck implements Flyable, Swimmable, Runnable {
  final String name;
  Duck(this.name);

  @override void fly()  => print(''$name is flying!'');
  @override void swim() => print(''$name is swimming!'');
  @override void run()  => print(''$name is running!'');

  @override double get maxAltitude => 100.0;
  @override double get maxDepth => 2.0;
  @override double get maxSpeed => 10.0;
}

// Penguin can only swim and run
class Penguin implements Swimmable, Runnable {
  final String name;
  Penguin(this.name);

  @override void swim() => print(''$name swims fast!'');
  @override void run()  => print(''$name waddles!'');

  @override double get maxDepth => 500.0;
  @override double get maxSpeed => 5.0;
}

void main() {
  var duck = Duck(''Donald'');
  duck.fly();   // Donald is flying!
  duck.swim();  // Donald is swimming!

  var penguin = Penguin(''Tux'');
  penguin.swim(); // Tux swims fast!

  // Type checking
  print(duck is Flyable);     // true
  print(penguin is Flyable);  // false
  print(penguin is Swimmable); // true
}
Output:
Donald is flying!
Donald is swimming!
Tux swims fast!
true
false
true

Abstract Classes as Interfaces

The most common pattern in Dart is to use abstract class to define interfaces. This gives you type checking via is and as, and you can add concrete helper methods:

abstract class Repository<T> {
  Future<T?> findById(int id);
  Future<List<T>> findAll();
  Future<T> save(T entity);
  Future<bool> delete(int id);

  // Concrete helper — uses abstract methods
  Future<bool> exists(int id) async {
    return await findById(id) != null;
  }
}

class UserRepository implements Repository<Map<String, dynamic>> {
  final Map<int, Map<String, dynamic>> _store = {};
  int _nextId = 1;

  @override
  Future<Map<String, dynamic>?> findById(int id) async => _store[id];

  @override
  Future<List<Map<String, dynamic>>> findAll() async => _store.values.toList();

  @override
  Future<Map<String, dynamic>> save(Map<String, dynamic> entity) async {
    var id = entity[''id''] as int? ?? _nextId++;
    _store[id] = {...entity, ''id'': id};
    return _store[id]!;
  }

  @override
  Future<bool> delete(int id) async => _store.remove(id) != null;
}

void main() async {
  var repo = UserRepository();
  await repo.save({''name'': ''Alice'', ''email'': ''alice@example.com''});
  await repo.save({''name'': ''Bob'',   ''email'': ''bob@example.com''});
  print(await repo.findAll());
  print(await repo.exists(1));  // true
  print(await repo.exists(99)); // false
}

Exercise

  1. Define abstract classes Readable, Writable, and Seekable. Create a FileStream class that implements all three.
  2. Define a Comparable<T>-like interface with compareTo(T other). Implement it on a Student class that compares by GPA.

Quiz

1. In Dart, what keyword is used to implement an interface?

  • A) extends
  • B) interface
  • C) implements ✅
  • D) uses

2. When you implement a class, do you inherit its method bodies?

  • A) Yes, all of them
  • B) Yes, only public ones
  • C) No — you must provide your own implementation for all members ✅
  • D) Only if you use @override

3. Can a Dart class implement more than one interface?

  • A) No — only one
  • B) Yes — multiple with implements A, B, C ✅
  • C) Only two
  • D) Only if they are abstract

Summary

Every Dart class implicitly defines an interface. Use implements to adopt the contract of one or more classes without inheriting their code. The implementing class must override every public member. Abstract classes are the preferred way to define interfaces in Dart because they support both abstract method signatures and concrete helper methods. Multiple interfaces can be implemented simultaneously, unlike the single-parent restriction of extends.

dartprogrammingintermediateoop
PreviousLesson 54: Static Members in DartNextLesson 56: Polymorphism in Dart
Back to All Tutorials