4 ms·
This is a total aside from someone who doesn't know Java... But why design Point so that you have to do: `Point point = new Point.Builder() .latitude(25.2
by nonethewiser 4y ago
This is a total aside from someone who doesn't know Java...
But why design Point so that you have to do:
`Point point = new Point.Builder()
.latitude(25.2012544)
.longitude(55.2569389)
.build();`
Instead of:
`Point point = new Point(25.2012544,55.2569389)`
Cool project btw... working with geospatial data can be fun.
- iampims 4y agoLess options for mixing latitude and longitude? I personally like static methods. Point point = Point.fromLonLat(55.25…, 25.20…); The builder pattern is useful to set defaults and add features without breaking backward compatibility.
- nonethewiser 4y ago> The builder pattern is useful to set defaults and add features without breaking backward compatibility. Ah, that is interesting. Did not think about that.
- oh_sigh 4y agoYou can also have cached static instances(assuming immutability), eg Point.fromLonLat(0,0) can always return the same instance, whereas new Point(0,0) must allocate and return a new instance.
- bfeynman 4y agobuilder patterns are very common now because they make maintainability a lot easier, (i.e. if god forbid someone accidentally swapped vars in list of inputsof the same type), and secondly because you can use an annotation library to generate the boilerplate for you, you don't have to write any of it. Although agreed it's used when you start to get to more parameters. I didn't check but it's possible there are a lot of null/default values like projection or something.
- deleted 4y ago[deleted]
- just_mc 4y agoBuilder patterns are most useful in statically typed languages that don't have strong support for optional parameters. In creating a Point, neither value is optional, so I would question the value versus the additional complexity in this case.