11

Just to be sure, has Dart removed explicitly defining an interface now in favor of implicitly defining it via abstract?

I see it mentioned in Dart and Interface Segregation Principle, however I'm also finding a lot of content still referencing the explicit definition, such as When to use interfaces in Dart?

nbro
  • 15,395
  • 32
  • 113
  • 196
Will Squire
  • 6,127
  • 7
  • 45
  • 57

2 Answers2

26

Yes. The interface keyword was removed from Dart. Instead all classes have implicit interfaces. So if you want to define an interface you can use an abstract class instead.

See this blog post from 2012 about eliminating the interface keyword.

Greg Lowe
  • 15,430
  • 2
  • 30
  • 33
0

Please note that the accepted answer is no longer true.

Dart 3 has re-introduced the interface keyword. See here: https://dart.dev/language/class-modifiers#interface

The semantic of this differs from what you might expect from your background in other languages like Java: In Dart, this is only a class modifier that ensures that code in other files (= "libraries" in Dart) can not extend this class but must implement it completely (or be abstract).

To get Java-like "pure" interfaces, use abstract interface