Factory Pattern Implementation
Relevant source files
The following files were used as context for generating this wiki page:
The Factory Pattern in the flext-target-oracle-wms project provides a structured and extensible mechanism for instantiating Oracle WMS targets. It abstracts the complexity of configuration validation, environment-specific presets, and monitoring integration, allowing developers to create production-ready target instances through a unified interface.
This implementation primarily resides within FlextTargetFactory and FlextTargetMonitoringFactory, leveraging Pydantic-based request models to ensure type safety and configuration integrity.
Sources: src/flext_target_oracle_wms/factory.py, examples/04_factory_usage.py:1-15
Core Factory Architecture
The factory system is divided into two primary classes: a base factory for standard target creation and a monitoring-enhanced factory that integrates with the project's observability suite.
FlextTargetFactory
This class handles the fundamental logic for target creation. It maintains a set of PRESETS (development, production, testing) and processes TargetCreationRequest objects. It supports creating targets from structured request models or raw configuration dictionaries.
FlextTargetMonitoringFactory
This class extends the creation logic by automatically wrapping target instantiation with monitoring capabilities. It utilizes the flext_monitor_function decorator to track the creation process and supports MonitoredTargetCreationRequest which includes additional metadata like monitor_name.
Sources: src/flext_target_oracle_wms/factory.py:18-80, tests/unit/test_oracle_wms_factory.py:1-40
Component Relationship Diagram
The following diagram illustrates the relationship between the factory classes, the models they consume, and the targets they produce.
Target Creation Flow
The creation process involves validating the input configuration, applying environment-specific presets, and instantiating the final target object.
- Request Initialization: A user provides authentication details (base URL, username, password) and optional environment/preset flags.
- Preset Application: The factory checks if a
presetis requested (e.g., "production") and merges preset-specific constants into the configuration. - Validation: The system ensures all required fields are present. Missing fields like
base_urlorpasswordresult in a failure result. - Instantiation: The
SingerTargetOracleWMS(or equivalent) is initialized with the resolved settings.
Configuration and Presets
The factory uses a centralized preset system to maintain consistency across different environments. These are typically stored in the project's constant definitions.
Available Presets
| Preset | Environment | Intended Use |
|---|---|---|
development | development | Local testing and feature development |
production | production | High-volume production WMS environments |
testing | testing | Automated CI/CD unit and integration tests |
Sources: src/flext_target_oracle_wms/_constants/factory.py, tests/unit/test_oracle_wms_factory.py:48-52
Configuration Parameters
The TargetCreationRequest model defines the schema for factory inputs:
| Parameter | Type | Required | Description |
|---|---|---|---|
base_url | str | Yes | The Oracle WMS Cloud SaaS URL |
username | str | Yes | WMS API Username |
password | str | Yes | WMS API Password |
environment | str | No | Target environment (default: development) |
preset | str | No | Named configuration preset to apply |
additional_config | dict | No | Arbitrary key-value pairs for advanced tuning |
Sources: tests/unit/test_oracle_wms_factory.py:18-40, examples/04_factory_usage.py:35-45
Implementation Example
The factory pattern is designed for ease of use in application entry points. The following snippet demonstrates creating a target using the monitored factory.
from flext_target_oracle_wms import FlextTargetFactory, FlextTargetOracleWmsModels
# Structured request approach
request = FlextTargetOracleWmsModels.TargetOracleWms.TargetCreationRequest(
base_url="https://wms.example.oraclecloud.com",
username="factory_user",
password="secure_password"
)
# Target creation
result = FlextTargetFactory.create_target(request)
if result.success:
target = result.value
logger.info("Successfully created target: %s", target.name)
Sources: examples/04_factory_usage.py:38-50, src/flext_target_oracle_wms/__init__.py:40-70
Performance Benchmarking
Performance tests verify that factory instantiation remains within acceptable thresholds, especially for high-frequency operations or dynamic target switching.
- Iteration Scaling: Tests run for
PERF_ITERATIONS(typically 1000+) to ensure no memory leaks or degradation during repeated factory calls. - Thresholds: Target creation is expected to complete within
PERF_THRESHOLD_SECto prevent bottlenecks in pipeline initialization.
Sources: tests/unit/test_benchmarks.py:75-95
Conclusion
The Factory Pattern implementation in flext-target-oracle-wms ensures that target creation is predictable, validated, and observable. By separating instantiation logic from business logic, the project supports complex configuration scenarios—such as switching between sandbox and production Oracle WMS environments—with minimal code changes.