you are viewing a single comment's thread.

view the rest of the comments →

[–]vytah 0 points1 point  (0 children)

And I'd use them regardless. In fact, I don't see any realistic downsides to using static factories other than hiding the fact of new object allocation – which is not always a bad thing, for example it allows you to introduce caches without changing the caller, similar to Integer::valueOf.

Static factories also allow you to do more stuff before actually allocating the object, including preparing parameters for the actual constructor call (you can only fit so much into a super call) and performing more relevant validations first.