Primitives: Foundational Design Patterns
This document describes the fundamental design patterns that serve as primitives in the NERV architecture - the basic building blocks from which more complex patterns and components are constructed.
Overview
While the NERV architecture defines its own higher-level patterns (Reactive Event Mesh, Temporal Versioning, etc.), these patterns are built upon well-established foundational design patterns from software engineering. These primitives form the atomic building blocks of our architecture - they are the basic elements from which all higher-level components are constructed.
Core Primitive Patterns
Pattern | Purpose | NERV Usage | Implementation Library |
---|---|---|---|
Observer | Enable notification of state changes | Event notification and reactive programming | Blinker |
Command | Encapsulate operations as objects | Explicit side effect management | Effect |
Monad | Encapsulate computation with context | Functional composition with effects | Effect |
Strategy | Define family of interchangeable algorithms | Runtime algorithm selection | Python protocols |
Builder | Construct complex objects step by step | Multi-stage object construction | Python dataclasses |
DAG | Organize nodes with dependencies | Dependency-based scheduling | TaskMap |
Factory | Delegate object creation to specialized methods | Object creation with configuration | Static methods |
Decorator | Add behavior to objects dynamically | Adding capabilities without inheritance | Python decorators |
Pattern Relationships to NERV Architecture
The primitives form the foundation for NERV’s higher-level architectural patterns:
NERV Pattern | Primitive Composition | Implementation Libraries |
---|---|---|
Reactive Event Mesh | Observer + Command + Factory | Blinker |
Temporal Versioning | Command + Decorator + Factory | Eventsourcing |
Perspective Shifting | Strategy + Decorator + Factory | Marshmallow |
State Projection | Command + Strategy + Builder | Pyrsistent |
Effect System | Command + Monad + Decorator | Effect |
Quantum Partitioning | Builder + DAG + Factory | TaskMap |
Key Primitive Implementations
Each primitive pattern is implemented using specific libraries within NERV:
- Observer Pattern: Blinker library for signal dispatch (EventBus)
- Command Pattern: Effect library for effect descriptions
- Monad Pattern: Effect library for monadic operations
- Strategy Pattern: Python protocols with Marshmallow for schema-based transformations
- Builder Pattern: Python dataclasses with builder methods in QuantumPartitioner
- DAG Pattern: TaskMap library for dependency execution
- Factory Pattern: Static factory methods on various domain classes
- Decorator Pattern: Python decorators and function wrappers for aspect-oriented programming
Implementation Guidance
When implementing NERV components, consider these primitive patterns:
- Favor composition over inheritance by using these patterns to combine behaviors
- Make interfaces explicit by clearly defining the pattern relationships
- Consider pattern combinations to solve complex problems
- Document pattern usage to explain design decisions and architecture
- Leverage library primitives when available to reduce custom implementation
Understanding these primitives is crucial for effective implementation of the NERV architecture, as they form the foundation upon which all higher-level patterns and components are built.
Cross-Cutting Architectural Properties
The primitive patterns combined in NERV create these emergent architectural properties:
Property | Description | Enabled By | Primary Libraries |
---|---|---|---|
Decoupling | Components can evolve independently | Observer, Command | Blinker, Effect |
Composability | Simple units combine into complex behaviors | Monad, Decorator | Effect, Python decorators |
Extensibility | New behaviors without changing core code | Strategy, Factory | Marshmallow, Python protocols |
Observability | Introspection of system behavior | Observer, Command | Blinker, Effect |
Parallelism | Efficient concurrent execution | DAG, Builder | TaskMap |
Flexibility | Runtime adaptation to changing needs | Strategy, Decorator | Marshmallow, Python decorators |
Learn More
For detailed explanations and implementation examples of each primitive pattern, see their individual documentation pages:
- Observer Pattern: Event notification system (Blinker)
- Command Pattern: Encapsulated operations (Effect)
- Monad Pattern: Computation with context (Effect)
- Strategy Pattern: Interchangeable algorithms (Python protocols)
- Builder Pattern: Step-by-step construction (Python dataclasses)
- DAG Pattern: Dependency management (TaskMap)
- Factory Pattern: Delegated object creation (Static methods)
- Decorator Pattern: Dynamic behavior addition (Python decorators)