Skip to content

1.1.0

Choose a tag to compare

@Traqueur-dev Traqueur-dev released this 10 Aug 17:47
· 20 commits to main since this release

πŸš€ Structura v1.1.0 – Polymorphic Configuration Support

Major feature release introducing polymorphic type resolution and improved registry architecture.

✨ New Features

πŸ”„ Polymorphic Configuration System

  • @Polymorphic annotation: 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 registries package
  • DefaultValueRegistry relocated to fr.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: DefaultValueRegistry moved to registries package
  • 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