Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General refactoring #7

Merged
merged 3 commits into from
Jul 20, 2024
Merged

General refactoring #7

merged 3 commits into from
Jul 20, 2024

Conversation

enovka
Copy link
Owner

@enovka enovka commented Jul 20, 2024

This pull request addresses the issue of code duplication and potential inconsistencies in the Gemini4j builder classes. It implements a comprehensive refactoring strategy to improve the library's maintainability, extensibility, and type safety.

Key Changes:

  • Hierarchical Abstraction: Introduced a hierarchy of abstract builder classes (AbstractBuilder, AbstractComplexBuilder, AbstractRequestBuilder, etc.) to encapsulate common functionality and reduce redundancy across concrete builders.
  • Generics: Utilized generics to create flexible builder classes capable of handling different request object types, enhancing code reusability.
  • Decoupled Builder Chains: Decoupled builder chains by removing the generic and() method from AbstractComplexBuilder and adding specific and() methods to concrete builders, ensuring type safety and clarity.
  • Refactored Resource Classes: Refactored AbstractResource and its implementations to maximize code reuse and minimize duplication. Introduced a generic type parameter for response handling and moved common request execution logic to the abstract class.
  • Corrected Model Name Format: Fixed an issue where the model field in EmbedContentRequest was not in the expected format, ensuring compatibility with the Gemini API.

Benefits:

  • Reduced Code Duplication: Eliminated redundant code, making the library more concise and easier to maintain.
  • Improved Type Safety: Enhanced type safety by using generics and specific and() methods, reducing the risk of runtime errors.
  • Enhanced Extensibility: Simplified the process of adding new builder classes for future API features.
  • Increased Consistency: Ensured consistent behavior and method naming across all builders.

This refactoring significantly improves the architecture of the Gemini4j library, making it more robust, maintainable, and scalable for future development.

@enovka enovka added the enhancement New feature or request label Jul 20, 2024
@enovka enovka added this to the Initial version (1.0.0) milestone Jul 20, 2024
@enovka enovka self-assigned this Jul 20, 2024
@enovka enovka merged commit bc489bd into phase-1 Jul 20, 2024
@enovka enovka deleted the general-refactoring branch September 2, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant