They added a few new modifiers to classes. What is the difference between abstract class, interface, and abstract interface?
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:
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 |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With