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

Feature: Enhance TCModelFactory with Custom GVL Support and Code Clarity #466

Open
harrykingriches opened this issue Jan 3, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@harrykingriches
Copy link

Issue: Enhance TCModelFactory with Custom GVL Support and Code Clarity

Currently, TCModelFactory offers two methods for creating TCModel instances: withGVL() and noGVL(). withGVL() generates a TCModel including the GVL, while noGVL() generates one without.

However, the current implementation has a few areas for improvement:

  1. Lack of Custom GVL Support: Both methods implicitly use GVLFactory.getLatest(). There's no way to provide a custom GVL, limiting flexibility for testing and specific use cases.

  2. Confusing noGVL() Parameter: The noGVL() method accepts a TCModel parameter, but its purpose is unclear and seemingly unused. This adds unnecessary complexity and confusion.

  3. Code Duplication and Readability: The logic for creating the base TCModel is duplicated within withGVL() and noGVL(). This hinders maintainability and makes the code harder to understand.

Proposed Solution:

  1. Introduce Custom GVL Parameter: Add an optional gvl parameter (of type GVL) to both withGVL() and noGVL(). If provided, this GVL will be used; otherwise, it defaults to GVLFactory.getLatest().

  2. Remove Unused TCModel Parameter from noGVL(): Eliminate the confusing and unused TCModel parameter from the noGVL() method.

  3. Refactor with Private createBaseTCModel() Method: Extract the shared logic for creating the base TCModel into a private method called createBaseTCModel(gvl?: GVL). Both withGVL() and noGVL() will then call this method, passing the provided or default GVL.

Benefits:

  • Increased Flexibility: Developers can now use custom GVLs with TCModelFactory, facilitating testing and specific scenarios.
  • Improved Code Clarity: Removing the unused parameter and refactoring with createBaseTCModel() simplifies the code and makes it easier to understand and maintain.
  • Reduced Code Duplication: Extracting the shared logic reduces redundancy and improves maintainability.

Example Usage:

// Using the latest GVL
const tcModelWithGVL = TCModelFactory.withGVL();
const tcModelNoGVL = TCModelFactory.noGVL();

// Using a custom GVL
const myGVL = // ... your custom GVL
const tcModelWithCustomGVL = TCModelFactory.withGVL(myGVL);
const tcModelNoGVLWithCustomGVL = TCModelFactory.noGVL(myGVL);
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

No branches or pull requests

1 participant