Answered step by step
Verified Expert Solution
Question
1 Approved Answer
we pointed out that using 'magic numbers' is poor programming practice, and we replaced them with named constants. This is listed in the literature as
we pointed out that using 'magic numbers' is poor programming practice, and we replaced them with named constants. This is listed in the literature as a standard refactoring rule [1], Replace magic number with symbolic constant, which involves the following steps: (a) Declare a constant and set it to the value of the magic number. (b) Find all occurrences of the magic number. C) See if magic number matches the usage of the constant; if yes, replace the magic number by the constant (d) Compile and test; code should work exactly as before. It has been noted that using named constants does not solve all problems since these can still be interpreted as numbers. A much safer approach in Java is to use the enum construct. Develop a refactoring process to replace named constants with enums and apply this to refactor the code developed for the Library so that the result codes returned by Library are all contained in a single enum named Library Results. (Hint: this will involve finding references to these named constants in all situations, which include variable declarations and return types of methods.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started