1.1.0
π Structura v1.1.0 β Polymorphic Configuration Support
Major feature release introducing polymorphic type resolution and improved registry architecture.
β¨ New Features
π Polymorphic Configuration System
@Polymorphicannotation: Enable automatic type resolution based on YAML keys- Type-safe polymorphic registries: Register multiple implementations for a single interface
- Automatic implementation detection: Resolve concrete types at runtime based on configuration data
- Custom key mapping: Configure which YAML field determines the implementation type
@Polymorphic(key = "type")
public interface DatabaseConfig extends Loadable {
String getHost();
int getPort();
}
// Register implementations
PolymorphicRegistry.create(DatabaseConfig.class, registry -> {
registry.register("mysql", MySQLConfig.class);
registry.register("postgres", PostgreSQLConfig.class);
});
// YAML automatically resolves to correct implementation
// type: mysql
// host: "localhost"
// port: 3306ποΈ Enhanced Registry Architecture
PolymorphicRegistry<T>: Type-safe registry for managing implementation mappings- Fluent configuration API: Clean, builder-style registry setup
- Case-insensitive resolution: Flexible type name matching
- Automatic class name registration: Register using simple class names
- Registry isolation: Separate registries per interface type
π§ Internal Improvements
- Reorganized package structure: Moved registries to dedicated
registriespackage DefaultValueRegistryrelocated tofr.traqueur.structura.registries- Enhanced error handling: More descriptive exceptions for registry operations
- Comprehensive test coverage: 250+ new test cases for polymorphic functionality
π API Reference
Registry Management
// Create and configure registry
PolymorphicRegistry.create(MyInterface.class, registry -> {
registry.register("impl1", Implementation1.class);
registry.register("impl2", Implementation2.class);
registry.register(Implementation3.class); // Auto-naming
});
// Retrieve registry
PolymorphicRegistry<MyInterface> registry = PolymorphicRegistry.get(MyInterface.class);
// Query implementations
Optional<Class<? extends MyInterface>> impl = registry.get("impl1");
Set<String> availableTypes = registry.availableNames();Polymorphic Annotation
@Polymorphic(key = "provider") // Custom key (default: "type")
public interface PaymentProvider extends Loadable {
void processPayment(double amount);
}π― Use Cases
- Plugin systems: Dynamically load different implementations based on configuration
- Service providers: Switch between payment processors, databases, etc.
- Environment-specific configs: Different implementations for dev/staging/prod
- Feature flags: Enable/disable functionality through configuration
- Modular architectures: Clean separation of interface and implementation
π‘οΈ Error Handling
- Registry validation: Prevents duplicate registrations and null values
- Type safety: Compile-time guarantees for polymorphic resolution
- Descriptive exceptions: Clear error messages for configuration issues
- Graceful fallbacks: Empty optionals for missing implementations
π¦ Migration Notes
- Package changes:
DefaultValueRegistrymoved toregistriespackage - No breaking API changes: Existing configuration code remains compatible
- Optional feature: Polymorphic support is opt-in via annotations
π§ͺ Quality Assurance
- Comprehensive test suite: 250+ tests covering core functionality and edge cases
- Type safety validation: Ensures registry isolation and type correctness
- Error scenario coverage: Validates exception handling and error messages
- Performance testing: Efficient registry lookup and resolution
Full Changelog: 1.0.3...1.1.0