D
OOP & SOLIDEasy20 XP3 min read

What is the difference between abstract class and interface in Dart?

TL;DR: Abstract classes can have method implementations and state; subclasses use extends and inherit them. Interfaces (abstract class used with implements, or Dart 3 interface keyword) are pure contracts — every method must be implemented from scratch.

Full Answer

Aspectabstract class + extendsinterface / implements
ImplementationInherits concrete methodsMust implement everything
StateFields are inheritedMust re-declare all fields
MultipleOnly one superclassCan implement many interfaces
Use caseShared base behavior (BaseBloc)Contracts (Repository, Service)
🎯

Dart 3 added the interface keyword for clarity. interface class Serializable {} forces any class using it to implement all methods, even in the same package.

Code Examples

dartabstract class vs interface
Output
// BaseRepository: cache logic inherited for free
// Logger: ConsoleLogger must implement both methods

Common Mistakes

  • Using an abstract class as a pure interface — in Dart, any class can be used with implements. Dart 3's interface keyword makes the intent explicit
  • Extending multiple abstract classes — not possible in Dart, use mixins instead

Interview Tip

💡

Show you know that in Dart, every class is implicitly an interface. Any class can be implements'd, even without the abstract modifier.

#abstract-class#interface#implements#extends