From the course: Agile Software Development: Refactoring
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Refactoring: Extract Constant numbers
From the course: Agile Software Development: Refactoring
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Refactoring: Extract Constant strings3m 19s
-
(Locked)
Refactoring: Extract Constant numbers2m 17s
-
(Locked)
Refactoring: Extract Variable/Extract Method3m 12s
-
(Locked)
Refactoring: Simplify Arithmetic2m 30s
-
(Locked)
Refactoring: Simplify Booleans2m 35s
-
(Locked)
Refactoring: Group-Related Logic5m 22s
-
(Locked)
Refactoring: Final steps3m 33s
-
Add new behavior to refactored code5m 16s
-
(Locked)
-