base, interface, and final Modifiers
Control how others extend your classes.
base, interface, and final Modifiers is a free Dart Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Class Modifiers
Dart 3 added modifiers that control how others reuse your class. They let a library author set clear, enforced boundaries.
The base Modifier
A base class can be extended but never implemented. This guarantees every subtype actually inherits your real implementation.
base class Animal {
void breathe() {}
}Why Use base
With base, you know all subtypes share your concrete code, so private members and invariants stay reliable across the hierarchy.
The interface Modifier
An interface class can be implemented but not extended from outside its library. Others promise the shape, not your code.
interface class Logger {
void log(String m) {}
}Why Use interface
The interface modifier is perfect for contracts. Callers implement your method signatures while you keep the implementation private.
class FileLogger implements Logger {
void log(String m) {}
}The final Modifier
A final class cannot be extended or implemented outside its library at all. The type is completely locked down.
final class Money {}Why Use final
Mark a class final when its behavior must never be changed by others. You stay free to evolve it without breaking subclasses.
base Spreads Down
If you extend a base class, your subclass must also be base, final, or sealed. The restriction flows down the chain.
base class Cat extends Animal {}Combining Modifiers
You can pair words like base mixin or sealed with others to fine-tune reuse rules. Each combination expresses a precise intent.
base mixin Swimmer {
void swim() {}
}Same-Library Freedom
These limits only apply outside the declaring library. Inside your own package, you can extend and implement as you like.
Picking the Right One
Choose interface for contracts, base for shared code, and final to lock things fully. Pick the loosest rule that still feels safe. 🧭
Quick Check
Quick check on class modifiers.
Recap
You learned that base forces inheritance, interface forces implementation, and final blocks both, giving you control over reuse. 🔐
Frequently asked questions
Is the “base, interface, and final Modifiers” lesson free?
Yes — the full text of “base, interface, and final Modifiers” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “base, interface, and final Modifiers”?
Control how others extend your classes. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “base, interface, and final Modifiers” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Final Fields and Deep Immutability
- sealed Classes and Exhaustive switch
- base, interface, and final Modifiers
- copyWith and Value Equality