How Replacing Hardcoded Values with Meaningful Constants Leads to Cleaner, Maintainable, and Less Error-Prone Code"
I claim to my students they don't use magical numbers even with the switch statements:
```java
switch(aVariable) {
case A_CONSTANT: ...
// more cases
}
```
The body of the setVolume method can be simplified with this one-line expression:
return Math.max(MIN_VOLUME, Math.min(level, MAX_VOLUME));
Nevertheless, sometimes it is preferable to write several lines (by including if , else if and else as you did) when the inline expression becomes a bit confused.
This is an opinionated refactoring.
Nice post! Thanks again, @JavinPaul and Soma!
I claim to my students they don't use magical numbers even with the switch statements:
```java
switch(aVariable) {
case A_CONSTANT: ...
// more cases
}
```
The body of the setVolume method can be simplified with this one-line expression:
return Math.max(MIN_VOLUME, Math.min(level, MAX_VOLUME));
Nevertheless, sometimes it is preferable to write several lines (by including if , else if and else as you did) when the inline expression becomes a bit confused.
This is an opinionated refactoring.
Nice post! Thanks again, @JavinPaul and Soma!