Principle:416rehman DeepZero Extensibility by Subclassing
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Extensibility |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
An extensibility model where new capabilities are added by subclassing typed base classes and registering them, rather than patching core logic or using configuration-only plugins.
Description
Extensibility by subclassing is a design principle where the system defines a small set of abstract base classes (the "contract"), and all extensions are concrete subclasses that implement the abstract methods. DeepZero uses this pattern in two places:
- Processors: subclass IngestProcessor, MapProcessor, ReduceProcessor, or BulkMapProcessor. The engine calls the abstract process() method; the subclass implements the domain logic.
- LLM Backends: subclass LLMBackend or CLIAgentBackend. The provider calls raw_complete(); the subclass implements the vendor-specific details.
The key advantages over alternatives:
- vs. configuration-only plugins: a subclass can express arbitrary logic, not just parameter variations. A processor that downloads a database, parses PE headers, or runs an external CLI cannot be expressed as YAML config.
- vs. monkey-patching: subclassing is type-safe and discoverable. The base class defines the contract; a missing method is caught at class definition time.
- vs. dependency injection frameworks: no DI container is needed. Registration is a single function call (register_processor or register_backend).
The registration step makes the subclass discoverable without the core importing it. Built-in processors are registered at import time; external processors are discovered by file path from the pipeline YAML. Third parties can register backends without modifying DeepZero.
Usage
Use this pattern when:
- Extensions need to express arbitrary logic, not just configuration
- The system should be extensible by third parties without patching core code
- Type safety and discoverability matter
- A small set of well-defined contracts (base classes) can cover the extension space
Theoretical Basis
# Abstract pattern (NOT real implementation)
# The contract (base class):
class Processor(ABC):
@abstractmethod
def process(self, ctx, entry) -> Result: ...
# The extension (subclass):
class MyProcessor(Processor):
def process(self, ctx, entry) -> Result:
# arbitrary domain logic here
return Result.ok(data={"my_output": computed_value})
# The registration (discovery):
register("my_processor", MyProcessor)
# Now usable in YAML: processor: my_processor