Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago