Last active
June 22, 2024 18:18
-
-
Save mcsee/ffba17263f40053ed57698d0880b942c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String handleMicrophoneState(String state) { | |
if (state.equals("off")) { | |
return "Microphone is off"; | |
} else { | |
return "Microphone is on"; | |
} | |
} | |
/* The constant representing the 'off' state is | |
duplicated throughout the code, | |
increasing the risk of typos and spelling mistakes. | |
The "else" condition doesn't explicitly check for the 'on' state; | |
it implicitly handles any state that is 'not off'. | |
This approach leads to repetition of the IF condition | |
wherever the state needs handling, | |
exposing internal representation and violating encapsulation. | |
The algorithm is not open for extension and closed for modification, | |
meaning that adding a new state | |
will require changes in multiple places in the code. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment