abstract interface class is a class declaration modifier that defines a strict type contract. It combines the constraints of the abstract keyword and the interface modifier to create a type that cannot be instantiated and can only be adopted via implementation, prohibiting inheritance via extension outside of its defining library.
Syntax
Semantic Rules
Theabstract interface class construct enforces the following technical constraints:
- Instantiation: The class cannot be instantiated. Attempting to create an instance via a constructor results in a compile-time error.
- External Inheritance: Classes outside the defining library cannot inherit from this class using the
extendskeyword. - Implementation: Classes (both internal and external to the library) must use the
implementskeyword to adopt the type. - Internal Inheritance: Within the defining library, the class may still be extended. This applies to the entire library scope, including parts spread across multiple files.
Member Implementation Behavior
Unlike a standardinterface in some other languages, a Dart abstract interface class may contain method bodies and fields. However, because the consuming class must use implements:
- The implementing class does not inherit the logic or state of the interface.
- Concrete implementing classes must override every field and method defined in the interface.
- Abstract implementing classes are not required to implement members immediately and may defer implementation to their subclasses.
- The implementing class cannot access
superto invoke the interface’s default behavior.
Code Example
Library Definition (storage.dart):
main.dart):
Master Dart with Deep Grasping Methodology!Learn More





