AnDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
abstract interface class in Dart is a class modifier combination that defines a contract strictly meant for implementation rather than inheritance outside its defining library, while preventing direct instantiation via generative constructors. It merges the non-instantiability of an abstract class with the subtyping restrictions of an interface class.
Core Mechanics
The behavior of anabstract interface class is governed by strict compiler rules based on library boundaries:
- Instantiation: Direct instantiation using generative constructors is prohibited globally. However, the class can define and be invoked via
factoryconstructors that return instances of concrete subtypes (similar to Dart’s built-inList). - Implementation (
implements): Permitted globally. Any class, regardless of the library it resides in, can implement the class’s interface. - Inheritance (
extends): Permitted only within the same defining library. External libraries are blocked from extending the class. - Member Definitions: Can contain both abstract members (without bodies) and concrete members (with bodies).
Syntax and Cross-Library Behavior
The following example demonstrates the structural enforcement of theabstract interface modifiers across different Dart libraries.
File: library_a.dart (Defining Library)
library_b.dart (Consuming Library)
Technical Characteristics
- Interface-Only Inheritance: When an external class uses the
implementskeyword on anabstract interface class, theimplementskeyword tells Dart to inherit only the class’s interface (its member signatures). The implementing class does not inherit any concrete behavior defined in the base class and must provide its own implementation for every member (methods, getters, setters). - Library Encapsulation: In Dart, a library is typically a single
.dartfile (along with any files included viapartdirectives). Theextendsrestriction of theinterfacemodifier is enforced exactly at this boundary. - Pattern Matching Exhaustiveness: Unlike
sealedclasses, anabstract interface classdoes not provide exhaustiveness checking for the compiler. Aswitchstatement evaluating subtypes of anabstract interface classwill require adefaultcase or wildcard, as the compiler cannot guarantee all possible implementations are known.
Master Dart with Deep Grasping Methodology!Learn More





