March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class NameTag { |
| | |
| | final String name; |
| | |
| | NameTag(String fullName) { |
| » | this.name = parse(fullName).toUpperCase(); |
| | } |
| | |
| | String parse(String fullName) { |
| | String[] components = fullName.split("[,| ]"); |
| | if (components == null || components.length < 2) { |
| | return fullName; |
| | } |
| | if (fullName.contains(",")) { |
| | return components[0]; |
| | } else { |
| | return components[components.length - 1]; |
| | } |
| | } |
| | } |
We’d like to end the book with a peculiar comparison. No matter what domain you’re in, your code’s just as good as your understanding of the real world and no better. And the real world is complex. That’s why you shouldn’t assume too much and make your code flexible to cope with being proven wrong.
The ...