Martin Fowler identifies long methods as another common code smell, fixable by breaking one long method into several smaller ones and composing them together. Since Clean Code emphasized writing short, meaningful methods, I had to look a bit to find one. But I’m not very happy with the board coordinate constructor:
1234567891011
publicUniversalBoardCoordinate(StringlocationPhrase)throwsInvalidCoordinateException{StringnoParens=locationPhrase.replace('(',' ').replace(')',' ');String[]coordinates=noParens.split(",");if(coordinates.length!=2){thrownewInvalidCoordinateException("That's not a valid board location.");}row=Integer.parseInt(coordinates[0].trim());column=Integer.parseInt(coordinates[1].trim());}
This is an easy refactor: think about what each line of code does, group the related ones in their own methods, and replace them. In fact, I’d already separated each group with a line break. The first two trim the input string and split it in two:
privatevoidcheckValidity(String[]coordinates)throwsInvalidCoordinateException{if(coordinates.length!=2){thrownewInvalidCoordinateException("That's not a valid board location.");}}