March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class Logbook { |
| | |
| | static final Path CAPTAIN_LOG = Paths.get("/var/log/captain.log"); |
| | static final Path CREW_LOG = Paths.get("/var/log/crew.log"); |
| | |
| » | void log(String message, boolean classified) throws IOException { |
| | if (classified) { |
| | writeMessage(message, CAPTAIN_LOG); |
| | } else { |
| | writeMessage(message, CREW_LOG); |
| | } |
| | } |
| | |
| | void writeMessage(String message, Path location) throws IOException { |
| | String entry = LocalDate.now() + " " + message; |
| | Files.write(location, Collections.singleton(entry), |
| | StandardCharsets.UTF_8, StandardOpenOption.APPEND); |
| | } |
| | } |
In general, a method should specialize on a single task only. Boolean method parameters show that a method does at ...