base modifier restricts a class to implementation inheritance. It disables the class’s implicit interface for external libraries, guaranteeing that all instances of the class or its subtypes contain the underlying concrete implementation and initialized state. This ensures that private state defined in the base class is instantiated, even though private members are not visible to or inherited by subclasses.
Syntax Declaration
Core Constraints
Thebase modifier imposes the following technical restrictions on the class and its dependents:
- Prohibited Interface Implementation: External libraries cannot use the
implementsclause with abaseclass. The compiler enforces that the class contract is fulfilled via inheritance (extends) rather than reimplementation. - Mixin Restrictions: A declaration of
base classprevents usage in awithclause. However, a class declared asbase mixin classpermits mixin usage, provided the consuming class adheres to subtype modifier restrictions. - Transitive Subtype Restriction: Any class that extends (or mixes in) a
basetype must itself be marked with one of the following modifiers to control further inheritance:basefinalsealed
Inheritance Mechanics
Becausebase enforces implementation inheritance, it prevents the creation of a subtype that bypasses the base class’s constructor or field initialization.
Valid Inheritance
A subclass extending abase class maintains the implementation contract and must declare its own restrictive modifier.
Invalid Operations
The compiler will emit static analysis errors for the following operations when performed outside the defining library:Base Mixins and Mixin Classes
While a standardbase class cannot be mixed in, the base modifier can be applied to mixins or mixin classes. This enforces the same transitive subtype restrictions: any class applying the mixin must be declared base, final, or sealed.
Master Dart with Deep Grasping Methodology!Learn More





