September 2019
Intermediate to advanced
816 pages
18h 47m
English
The Execute Around pattern tries to eliminate the boilerplate code that surrounds specific tasks. For example, the tasks specific to a file need to be surrounded by code for the purpose of opening and closing the file.
Mainly, the Execute Around pattern is useful in scenarios that imply tasks that take place inside a resource open-close lifespan. For example, let's assume that we have a Scanner and that our first task consists of reading a double value from a file:
try (Scanner scanner = new Scanner( Path.of("doubles.txt"), StandardCharsets.UTF_8)) { if (scanner.hasNextDouble()) { double value = scanner.nextDouble(); }}
Later on, another task consists of printing all double values:
try (Scanner ...