Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do the new class modifiers work in Dart 3.0 (interface vs abstract)?

Tags:

flutter

dart

They added a few new modifiers to classes. What is the difference between abstract class, interface, and abstract interface?

like image 524
Kyle Venn Avatar asked Oct 11 '25 12:10

Kyle Venn


1 Answers

The official docs are pretty thorough, but here's super short summary. For a longer summary, check out the bottom of this post.

The first thing you need to get is the difference between implements and extends. These concepts existed in Dart 2.x, but get expanded on.

implements = Your sub-class has the exact same “shape” (fields/functions) as the parent class but must define all its own behavior. You do not inherit any functionality from the parent's functions or fields. It’s similar to other languages, but you can implement just about any class (regardless of modifier)

extends = Your sub-class can extend (override) behavior, inherit behavior, and implement behavior

Then this table summarizes the differences: enter image description here

Here is the full table from the spec:

Declaration Construct? Extend? Implement? Mix in? Exhaustive?
class Yes Yes Yes No No
base class Yes Yes No No No
interface class Yes No Yes No No
final class Yes No No No No
sealed class No No No No Yes
abstract class No Yes Yes No No
abstract base class No Yes No No No
abstract interface class No No Yes No No
abstract final class No No No No No
mixin class Yes Yes Yes Yes No
base mixin class Yes Yes No Yes No
abstract mixin class No Yes Yes Yes No
abstract base mixin class No Yes No Yes No
mixin No No Yes Yes No
base mixin No No No Yes No
like image 70
Kyle Venn Avatar answered Oct 14 '25 12:10

Kyle Venn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!