From the course: Practical Test-Driven Development for Java Programmers
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Restructuring code
From the course: Practical Test-Driven Development for Java Programmers
Restructuring code
- So now that we've introduced the ideas of long and short ISBNs, I think it'd be sensible to rename these methods to say, is this a valid short ISBN, and is this a valid long ISBN. So let's do that, and again I'm going to use Eclipse's Refactor, Rename, so that all calls to this method are also updated. So, this is going to become IsThisAValid rather then 10-digit, it will be Short, ISBN. And we can see the call to that method's been changed as well, and down here we'll rename this one to IsThisAValidLongISBN. Let's re-run our tests, and again just make sure we've not broken anything. Fine. Now, we've got two bits of code that are checking to see that when you divide the total by the relevant multiplier, it equals zero. And actually, this expression within brackets should evaluate to true or false. So rather than having to have this as an if statement, what we should be able to do is just return this value. So I think we should be able to do return, the total, modulus the relevant…
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.