> ## 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 Interface Class

An `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

The `interface` 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.

```dart theme={"dark"}
// Concrete interface class: Can be instantiated.
interface class ConcreteInterface {
  void execute() => print('Executing');
}

// Abstract interface class: Cannot be instantiated.
abstract interface class PureInterface {
  void execute();
}
```

## Technical Rules and Behaviors

1. **Implementation (`implements`)**: Any class, regardless of the library it resides in, can implement an `interface class`. The implementing class must define all members of the interface.
2. **Inheritance (`extends`)**: A class located in a *different* library cannot extend an `interface class`. Attempting to do so results in a compile-time error.
3. **Same-Library Exemption**: Within the exact same library (file) where the `interface class` is declared, the class *can* be extended. The inheritance restriction only applies across library boundaries.
4. **Instantiation**: Unlike interfaces in languages like Java or C#, a Dart `interface class` can be instantiated directly using its constructor, provided it is not marked with the `abstract` modifier.

## Boundary Enforcement Example

The following example demonstrates the compiler enforcement of the `interface class` across library boundaries.

```dart theme={"dark"}
// --- library_a.dart 
interface class Processor {
  void process() => print('Default processing');
}

// VALID: Extending is permitted within the same defining library.
class SubProcessor extends Processor {
  @override
  void process() => print('Sub processing');
}


// --- library_b.dart 
import 'library_a.dart';

// VALID: External libraries can implement the interface class.
class CustomProcessor implements Processor {
  @override
  void process() => print('Custom processing');
}

// ERROR: External libraries cannot extend an interface class.
// class InvalidProcessor extends Processor {} 

// VALID: Concrete interface classes can be instantiated externally.
void main() {
  Processor defaultProcessor = Processor(); 
}
```

## Modifier Compatibility

The `interface` 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).

<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>
