From the course: Agile Software Development: Refactoring

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Refactoring: Extract Constant numbers

Refactoring: Extract Constant numbers

From the course: Agile Software Development: Refactoring

Start my 1-month free trial

Refactoring: Extract Constant numbers

- [Instructor] I've gone ahead and refactored all of the hard-coded strings. I've included a copy of my code so you can begin at the same point as me. The next easy micro refactoring for us to do is to extract many of the hard-coded numbers into constants. So I'm thinking about these numbers like 50, 11, and six for example. I'm not sure that all of the hard-coded numbers need to be refactored, but these in particular seem like they're important to the business logic. Let's start with 50. We'll right-click on 50, select Refactor, Extract, Constant. Give the constant a name, I think 50 represents MAXIMUM_QUALITY. This and that could be a good name for it. We'll select Replace all occurrences, and press enter. And as expected, IntelliJ replaced all occurrences of the number 50, with the new constant, MAXIMUM_QUALITY. If we scroll up to the top of the file, in line seven, we see the new constant's definition. Let's go over to GildedRoseTest, and we'll notice that IntelliJ did not…

Contents