I was going through Effective java item 1, where "Static factories vs constructors" is discussed. One of the disadvantages mentioned is the following:
"The main disadvantage of static factories is that classes without public or protected constructors cannot be extended."
It is also mentioned that this is good since it will promote object composition to inheritance. However, is it not a serious limitation, when you indeed want inheritance? Why should I prefer static factories, when I do not know from before if the class is going to be extended or not?
Aucun commentaire:
Enregistrer un commentaire