-
Notifications
You must be signed in to change notification settings - Fork 997
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
dependecy-injection-injector-hw #715
base: main
Are you sure you want to change the base?
dependecy-injection-injector-hw #715
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good solution, let's improve it)
Map<Class<?>, Class<?>> interfaceImplementations = Map.of( | ||
ProductParser.class, ProductParserImpl.class, | ||
FileReaderService.class, FileReaderServiceImpl.class, | ||
ProductService.class, ProductServiceImpl.class | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this map a class-level field and initialize it once
if (interfaceClazz.isInterface()) { | ||
return interfaceImplementations.get(interfaceClazz); | ||
} | ||
return interfaceClazz; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can improve your solution using ternary
if (clazzImplementationInstance == null) { | ||
clazzImplementationInstance = createNewInstance(clazz); | ||
} | ||
return clazzImplementationInstance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can improve your solution using ternary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
No description provided.