Skip to main content
An abstract final class in Dart is a class modifier combination that establishes a strictly closed type hierarchy. It prevents the class from being instantiated globally, while simultaneously restricting inheritance (extends) and implementation (implements) exclusively to the library in which it is defined.

Technical Mechanics

The behavior of this construct is the exact intersection of its two modifiers:
  • abstract: Instructs the compiler to prohibit direct instantiation of the class. It permits the declaration of abstract members (methods, getters, setters) that lack an implementation, forcing valid subclasses to provide them.
  • final: Instructs the compiler to close the class to external derivation. No class outside of the defining library’s URI can use the class in an extends or implements clause. (Note: An abstract final class can never be used in a with clause, as Dart does not permit the final modifier on mixins or mixin classes).

Syntax and Scope Rules

Within the defining library (base_library.dart):
Outside the defining library (external_library.dart):

Compiler Characteristics

  • Constructors: An abstract final class can declare generative constructors. However, because the class cannot be instantiated directly, these constructors can only be invoked via super() calls from subclasses defined within the exact same library.
  • Exhaustiveness Checking: Unlike sealed classes (which are implicitly abstract and share the same library-restriction rules), abstract final classes do not trigger exhaustiveness checking in switch statements or expressions. The compiler will not enforce that all subtypes are handled when switching over an abstract final type.
  • Subtype Modifiers: Subclasses of an abstract final class within the same library must explicitly declare their own modifiers (base, final, or sealed) to maintain the integrity of the restricted hierarchy.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More