Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Chap. 7, we pointed out that using magic numbers is poor programming practice, and we replaced them with named constants. This is listed in

In Chap. 7, 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 LibraryResults. (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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions