March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class BoardComputer { |
| | |
| | CruiseControl cruiseControl; |
| | |
| | void authorize(User user) { |
| | Objects.requireNonNull(user); |
| » | if (user.isUnknown()) { |
| | cruiseControl.logUnauthorizedAccessAttempt(); |
| | } else if (user.isAstronaut()) { |
| | cruiseControl.grantAccess(user); |
| | } else if (user.isCommander()) { |
| | cruiseControl.grantAccess(user); |
| | cruiseControl.grantAdminAccess(user); |
| | } |
| | } |
| | } |
We’ve emphasized a few times already that understandability is absolutely critical for your code. By structuring your conditional branches in a symmetrical way, you’ll make the code easier to understand and easier to grasp. Whoever maintains such code in the future (chances are it’ll be you) will be able to locate features more quickly, ...