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

Small cleanup from PR #724 #750

Open
hohwille opened this issue Nov 11, 2024 · 0 comments · May be fixed by #762
Open

Small cleanup from PR #724 #750

hohwille opened this issue Nov 11, 2024 · 0 comments · May be fixed by #762
Assignees
Labels
enhancement New feature or request git good first issue Good for newcomers

Comments

@hohwille
Copy link
Member

hohwille commented Nov 11, 2024

From PR #724 see the review comment discussion:

default -> throw new IllegalArgumentException("Unsupported protocol: " + this);

I am not sure if the default case can actually occur, because if the enum is set incorrectly, then a IllegalArgumentException is thrown by the Enum class before.

This is a common problem pattern. The best way to solve this in an enum is to avoid the switch at all:
simply make the method abstract and create a method implementation for each enum constant.
This way, if new enum constants are added, the compiler will force the developer to implement the abstract method and he cannot forget it due to the compiler error.
I will create a small cleanup story for this improvement but we can already merge this PR as planned.

This should be cleaned up with this story.

@hohwille hohwille added enhancement New feature or request git labels Nov 11, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in IDEasy board Nov 11, 2024
@hohwille hohwille added the good first issue Good for newcomers label Nov 11, 2024
@leonrohne27 leonrohne27 self-assigned this Nov 12, 2024
@leonrohne27 leonrohne27 moved this from 🆕 New to 🏗 In progress in IDEasy board Nov 12, 2024
leonrohne27 added a commit to leonrohne27/IDEasy that referenced this issue Nov 14, 2024
Removed switch and created a method implementation for each enum constant instead and made it abstract
KianRolf added a commit to leonrohne27/IDEasy that referenced this issue Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request git good first issue Good for newcomers
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

2 participants