Question: Examine the following code: https://github.com/ShmilyJxu/Shared/tree/main/SRP-Code/src. One implication of SRP is that there should only be one reason to change a class. If you have more
Examine the following code: https://github.com/ShmilyJxu/Shared/tree/main/SRP-Code/src.
One implication of SRP is that there should only be one reason to change a class. If you have more than one reason, then the class should be refactored into multiple classes.
Give the above code, what are the problems regarding SRP? What will happen if we must change the way a bill is calculated? What about if we want to generate a new type of report?
Finally, consider what will happen if we have not clearly defined the responsibility of a class.
Do the following:
- Identify the pieces of the class that need to be changed to meet SRP.
- Refactor the code creating two new classes (calculate bills, write report), each with a single responsibility and then modify main() to implement the new classes. Test that your code produces the same results as the initial code. Provide your refactored code for the answer to Q1.
Step by Step Solution
There are 3 Steps involved in it
The code you provided violates the Single Responsibility Principle SRP To address this lets identify and refactor the parts of the code that violate S... View full answer
Get step-by-step solutions from verified subject matter experts
