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.
interface class in Dart is a class modifier that permits external libraries to implement the class’s API while strictly prohibiting them from extending it through inheritance. This enforces a contract where external consumers can only provide their own implementations of the interface, ensuring the original class’s internal implementation details and inheritance hierarchy remain isolated to its defining library.
Syntax
Theinterface modifier is placed directly before the class keyword. It can be used on its own to create a concrete class, or combined with the abstract modifier to create an uninstantiable contract.
Technical Rules and Behaviors
- Implementation (
implements): Any class, regardless of the library it resides in, can implement aninterface class. The implementing class must define all members of the interface. - Inheritance (
extends): A class located in a different library cannot extend aninterface class. Attempting to do so results in a compile-time error. - Same-Library Exemption: Within the exact same library (file) where the
interface classis declared, the class can be extended. The inheritance restriction only applies across library boundaries. - Instantiation: Unlike interfaces in languages like Java or C#, a Dart
interface classcan be instantiated directly using its constructor, provided it is not marked with theabstractmodifier.
Boundary Enforcement Example
The following example demonstrates the compiler enforcement of theinterface class across library boundaries.
Modifier Compatibility
Theinterface modifier dictates the external inheritance contract. Therefore, it is mutually exclusive with other modifiers that dictate external inheritance or implementation rules:
- Valid combinations:
abstract interface class - Invalid combinations:
base interface class,final interface class,sealed interface class(these result in syntax errors).
Master Dart with Deep Grasping Methodology!Learn More





