abstract modifier that cannot be directly instantiated. It serves as a structural blueprint, allowing developers to define a strict contract of methods and properties that derived classes must implement, while optionally providing shared concrete state and behavior.
Syntax and Instantiation
To declare an abstract class, prepend theclass keyword with abstract. Attempting to instantiate an abstract class using a generative constructor results in a compile-time error.
Abstract Methods
Abstract classes can contain abstract methods—method signatures that lack a body (implementation). These are defined by terminating the method signature with a semicolon instead of a code block. Any concrete class extending the abstract class is strictly required to provide an implementation for all inherited abstract methods.Concrete Members
Unlike pure interfaces in some other languages, Dart abstract classes can contain concrete state and behavior. They can declare fields, standard methods with bodies, getters, setters, and constructors.extends vs. implements
Because every class in Dart implicitly defines an interface, abstract classes can be utilized in two distinct ways by derived classes:
-
Using
extends(Inheritance): The subclass inherits the concrete methods and state of the abstract class. The subclass is only required to override the abstract methods. It must also call the abstract class’s constructor viasuperif a non-default constructor is defined. -
Using
implements(Interface Contract): The subclass treats the abstract class strictly as an interface. It inherits no implementation or state. The subclass must override all members defined in the abstract class, including concrete methods, getters, setters, and fields.
Factory Constructors in Abstract Classes
While an abstract class cannot be instantiated directly via a generative constructor, it can define afactory constructor. This allows the abstract class to return an instance of a concrete subclass when the constructor is invoked, bypassing the instantiation restriction.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





