How To Define an Interface in Dart

Last reviewed in January 2020 by Frank Treacy

Dart defines implicit interfaces. What does this mean?

In your app you'd have:

class Session {
  authenticate() { // impl }
}

or

abstract class Session {
  authenticate();
}

And for example in tests:

class MockSession implements Session {
  authenticate() { // mock impl }
}

No need to define a separate interface, just use regular or abstract classes!

Want to know EVERYTHING about Dart constructors? Check out Deconstructing Dart Constructors!

The best from the Flutter-verse in 3 minutes or less? Join Snacks!

Delivered twice monthly. No link walls. No spam. EVER.