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
Code repetition in Flyweight/README.md #2546
Comments
LOL nice, i wanna work on this issue |
wait i dont think moving that part out will work because, lets say if the input doesnot match the condition it will show default section which is nothing but if you move the "potions.put(type, potion);" out it will execute irrespective of the user input |
An exception can be thrown in the default case |
Exception for what, Invalid argument? |
Well yeah. But we don't need to consider a lot about the Exception since we are talking about design patterns here 😅 |
Yeah if we create an exception there, it will halt the normal execution and will show the error on console which will ruin the whole code flow ig |
This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions. |
This code snippet demonstrates the creation of a potion using the PotionType class. The PotionType is an enum with four fixed values. By utilizing the new Pattern Matching for Switch. Something like that : if (potion == null) {
potion = switch (type) {
case HEALING -> new HealingPotion();
case INVISIBILITY -> new InvisibilityPotion();
case STRENGTH -> new StrengthPotion();
case HOLY_WATER -> new HolyWaterPotion();
case POISON -> new PoisonPotion();
};
potions.put(type, potion);
} Please let me know if I’m on the right track or if you have any further suggestions. |
is this issue still open? |
This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions. |
The following code line is repeating.
Suggestion: It can be taken out of the switch-case statement.
The text was updated successfully, but these errors were encountered: