Categories
Software Craftsmanship

Builder pattern without getters

I like builders. If you’ve ever seen a constructor with ten parameters, eight of which can be null, you probably like builders, too. While this pattern is quite verbose, it is elegant. After doing some work with builders, I found myself wondering. Why are getters ever used in these? From Single Responsibility Principle point of […]

Categories
Software Craftsmanship

Switch-case data conversion in Java

Probably every programmer knows switch-case keywords. They are often used to convert data, e.g. some string from another (sub)system to your enum. While working with those, I found two patterns I call best practices. The first one uses return outright. Its code is short and elegant: However, some might argue it doesn’t follow the single-exit […]

Categories
Software Craftsmanship

Processing a result set of a LEFT JOIN

When you work with queries that involve a LEFT JOIN on a 1:n relation, you usually want to map the parent to a collection of its child elements. Imagine a simple example, a result set with two columns, daddy and kiddo (order by daddy). Try solving this problem with some pseudo-code before you read any […]