Eh? How’s that work. I’m not going to sit here and say there isn’t too many factories in Java but as a concept it’s extremely useful. You hand off a “factory” to something which actually creates the object. This is really useful in for example serialization. How so? You could register factories (mapped to some sort of ID) which get passed the serialized data and return some sort of created object. Now the core serialization code doesn’t know nor care how exactly any particular type gets serialized. Pretty nifty huh?
Some languages have better ways to encapsulate this functionality but that’s what the factory concept is
OOP is great, and can be much simpler than what you’ve seen.
It’s Java culture that’s terrible. The word “Factory” is a code smell all on its own.
Just like any tool, don’t overuse it. Don’t force extra layers of abstraction.
Why is the word factory a code smell?
It means you’re compensating for the lack of optional/named parameters in your language.
Sounds like you’re thinking more about the builder pattern.
Eh? How’s that work. I’m not going to sit here and say there isn’t too many factories in Java but as a concept it’s extremely useful. You hand off a “factory” to something which actually creates the object. This is really useful in for example serialization. How so? You could register factories (mapped to some sort of ID) which get passed the serialized data and return some sort of created object. Now the core serialization code doesn’t know nor care how exactly any particular type gets serialized. Pretty nifty huh?
Some languages have better ways to encapsulate this functionality but that’s what the factory concept is