4 ms·
I've read that book, and it felt very childish and condescending. Design patterns cannot be applied in every language. While some patterns are applicable every
by Kwpolska 10mo ago
I've read that book, and it felt very childish and condescending.
Design patterns cannot be applied in every language. While some patterns are applicable everywhere, many of them provide replacements for missing language features. For example, the Builder pattern is not very useful in languages with default parameters and named arguments.
- microtherion 10mo agoI'm not sure what Builder would have to do with default parameters and named arguments. Builder is extremely useful to pair with a parser, e.g. SAX. The parser parses the input, and the builder then decides what to do with it.
- Kwpolska 10mo agoHere is an example of the Builder pattern that illustrates my point: https://www.baeldung.com/java-builder-pattern#bd-classic-builder-pattern https://www.baeldung.com/java-builder-pattern#bd-classic-bui... Let’s remove the category argument and you get this: Post post = new Post.Builder() .title("Java Builder Pattern") .text("Explaining how to implement the Builder Pattern in Java") .build(); This builder is a more readable alternative to this: Post post = new Post("Java Builder Pattern", "Explaining how to implement the Builder Pattern in Java", null); But if Java supported named arguments and default values (the default would be null), this could just be: Post post = new Post(title: "Java Builder Pattern", text: "Explaining how to implement the Builder Pattern in Java");
- vips7L 10mo agoFunny part is that Java does have named parameters, but only for annotations!