Effective Java wrote:One advantage of static factory methods is that, unlike constructors, they have names
Effective Java wrote:A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they're invoked
Effective Java wrote:A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type
Effective Java wrote:A fourth advantage of static factories is that the class of the returned object can vary from call to call as a function of the input parameters
Effective Java wrote:A fifth advantage of static factories is that the class of the returned object need not exist when the class containing the method is written
Effective Java wrote:The main limitation of providing only static factory methods is that classes without public or protected constructors cannot be subclassed
Effective Java wrote:A second shortcoming of static factory methods is that they are hard for programmers to find
Tim Driven Development | Test until the fear goes away
Liutauras Vilda wrote:If to pass just parsed JsonObject and later extract attributes in the same way as in Version1, then again, Version2 looks somewhat more complicated to me with not much benefit.
Junilu Lacar wrote:Sorry, Liutauras, but the names are supposed to help the reader understand the idea being represented in the code.
βThe strongest of all warriors are these two β Time and Patience.β β Leo Tolstoy, War and Peace
Pete Letkeman wrote:Mooo!
Your posting was just mentioned in the June 2018 CodeRanch Journal and for that you get a cow.
Gerard Charles wrote:If the only purpose of the class is to return a map of column titles from a json String, why have a class at all? Just code it in a single method.
...if the purpose of the class to provide a Map from a json String, why not have the class implement Map<>?
Gerard Charles wrote:put and remove are optional methods, so you don't have to implement them. Java provides an umodifiable map API to make it easy to provide read only maps.
Everyone is a villain in someone else's story. Especially this devious tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|