> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Abstract Final Class

An `abstract final` class in Dart is a class modifier combination that establishes a strictly closed type hierarchy. It prevents the class from being instantiated globally, while simultaneously restricting inheritance (`extends`) and implementation (`implements`) exclusively to the library in which it is defined.

## Technical Mechanics

The behavior of this construct is the exact intersection of its two modifiers:

* **`abstract`**: Instructs the compiler to prohibit direct instantiation of the class. It permits the declaration of abstract members (methods, getters, setters) that lack an implementation, forcing valid subclasses to provide them.
* **`final`**: Instructs the compiler to close the class to external derivation. No class outside of the defining library's URI can use the class in an `extends` or `implements` clause. (Note: An `abstract final` class can never be used in a `with` clause, as Dart does not permit the `final` modifier on mixins or mixin classes).

## Syntax and Scope Rules

**Within the defining library (`base_library.dart`):**

```dart theme={"dark"}
// base_library.dart

abstract final class CoreComponent {
  // Abstract member declaration allowed
  void initialize(); 
  
  // Concrete member allowed
  void dispose() {
    print('Disposed');
  }
}

// ALLOWED: Extending within the same library.
// Subtypes must be marked base, final, or sealed.
final class NetworkComponent extends CoreComponent {
  @override
  void initialize() => print('Network ready');
}

// ALLOWED: Implementing within the same library.
// Subtypes must be marked base, final, or sealed.
base class UIComponent implements CoreComponent {
  @override
  void initialize() => print('UI ready');
  
  @override
  void dispose() => print('UI disposed');
}
```

**Outside the defining library (`external_library.dart`):**

```dart theme={"dark"}
// external_library.dart
import 'base_library.dart';

void main() {
  // ERROR: Abstract classes cannot be instantiated.
  // CoreComponent component = CoreComponent(); 
}

// ERROR: The class 'CoreComponent' can't be extended outside of its library because it's a final class.
final class CustomComponent extends CoreComponent {
  @override
  void initialize() {}
}

// ERROR: The class 'CoreComponent' can't be implemented outside of its library because it's a final class.
base class MockComponent implements CoreComponent {
  @override
  void initialize() {}
  @override
  void dispose() {}
}
```

## Compiler Characteristics

* **Constructors:** An `abstract final` class can declare generative constructors. However, because the class cannot be instantiated directly, these constructors can only be invoked via `super()` calls from subclasses defined within the exact same library.
* **Exhaustiveness Checking:** Unlike `sealed` classes (which are implicitly abstract and share the same library-restriction rules), `abstract final` classes **do not** trigger exhaustiveness checking in `switch` statements or expressions. The compiler will not enforce that all subtypes are handled when switching over an `abstract final` type.
* **Subtype Modifiers:** Subclasses of an `abstract final` class within the same library must explicitly declare their own modifiers (`base`, `final`, or `sealed`) to maintain the integrity of the restricted hierarchy.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
