6
I’ve been doing some research on this subject after I read in Joshua Block’s book, Effective Java, Item 1, about the use of static factory methods rather than building builders. There in the text he defends the use, whenever possible and cites, among other justifications, the possibility of implementing the standards Singleton or Flyweight. Also cite the case of the Class Boolean
, who wisely uses the Flyweight through the method valueOf(boolean)
:
public static Boolean valueOf(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}
My question is: I understand the advantages of using these Patterns, but would it not be possible to implement them in the constructor itself? Their use alone does not justify the creation of a static factory method.
And how do you deal with the issue of addiction injection when you become the private builder? It is possible to use DI when using this instance building strategy?
– dellasavia
It’s something else, but it bears some resemblance.
– Maniero