▲ | nunobrito a day ago | |||||||
That is just a coding style. I don't use factories in Java, they are just confusing when there are simpler ways to get the job done. | ||||||||
▲ | munksbeer 18 hours ago | parent | next [-] | |||||||
Factories are a pattern that is not unique to Java. They're used prolifically in C++ at least, and I'm sure in other languages. The factory pattern is tightly coupled with polymorphism. If you're not using polymorphism, then you may not typically need factories. But if you are, then at some point you're going to have some conditional logic about what concrete type of class you're going to create of a particular interface. Modern Java is lending itself more towards data oriented programming, and coders are trending in that direction. This may or may not last, like every trend. But even then, at the moment this tends to still involve using sealed interfaces and records, so you still have some form of instance creation and polymorphism. How do you avoid factories? Doesn't you code end up littered with worse code? | ||||||||
| ||||||||
▲ | bawolff 21 hours ago | parent | prev [-] | |||||||
I agree that you can write java any way you want. My point is that the protypical hello world is a cultural artifact representing the cultural ideals of the java language designers. Its symbolic of what they thought was good programming at the time the language was designed. So it says something about both the language design and the culture surounding the language. Or at least it did 20 years ago. That doesn't mean every java program follows that ideal. |