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

refactor: use static lookup methods #69

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

pcvolkmer
Copy link
Collaborator

Since all lookup classes use immutable data, this replaces creating new objects at runtime with the use of static methods.

Since all lookup classes use immutable data, this
replaces creating new objects at runtime with the use
of static methods.
@pcvolkmer
Copy link
Collaborator Author

Notice: If you plan to use a "term server" as mentioned in #65 (comment), this PR should not be merged.

A testable lookup class will eventually make use some kind of REST client and therefore needs a dependency of a REST client, witch has to be provided at runtime using DI, e.g.:

public class BeurteilungResidualstatusVsLookup {

  private RestTemplate restTemplate;

  public BeurteilungResidualstatusVsLookup(RestTemplate restTemplate) {
    this.restTemplate = restTemplate;
  }

  public final String lookupDisplay(String code) {
    this.restTemplate.getForEntity( ... )
    // .. handle response ...
  }
}

Test classes could provide TestRestTemplate to simulate a HTTP response.

If using static lookup methods, the injection and use of a RestTemplate is not possible any more on object creation at runtime, but lookup classes can be used as Spring Beans instead, using @Component annotation, witch will also result in some kind of singleton/prototyped objects.

As an alternative, you could use a second argument holding a reference to the RestTemplate, but his looks some kind of wierd:

public static String lookupDisplay(String code, RestTemplate restTemplate) {
  restTemplate.getForEntity( ... )
  // .. handle response ...
}

@chgl
Copy link
Contributor

chgl commented Aug 13, 2024

I think its fine to merge this as well, a nice refactoring. But more effort should definitely depend on if we move forward with #70

@chgl chgl requested a review from MarcelErpi August 13, 2024 13:05
@chgl chgl requested review from chgl and removed request for MarcelErpi August 20, 2024 09:58
@chgl chgl merged commit 7a0c3ab into bzkf:master Aug 20, 2024
15 checks passed
@pcvolkmer pcvolkmer deleted the static_lookup_methods branch August 28, 2024 18:41
@miracum-bot
Copy link
Collaborator

🎉 This PR is included in version 2.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants