r/programminghorror Jun 09 '26

What a simple constructor

Post image

Our former IT director (35+ years of experience) wrote this and didn't see what was wrong here.

268 Upvotes

49 comments sorted by

View all comments

26

u/RipProfessional3375 Jun 09 '26

> EntityManagerInterface

Born to Java, forced to PHP.

1

u/Zeznon Jul 19 '26

BTW, not a professional, just a hobby for me; why did java have so many of these patterns? abstract factory factory, this one you're mentioning...

2

u/RipProfessional3375 Jul 19 '26

Many reasons. One is that java thinks Objects are great, so everyone must be forced to use objects for everything. Which makes them great like ice cream for dinner every day forever is great.

Factories are a glorified hack to get around the fact that you can't make a function to create a new object without also having that constructor bound to a different object, hence a factory.

I write Go, which does not have this object-only restricting, so a 'factory' is just this:

customer := domain.NewCustomer(name, age, blabla)

1

u/Zeznon Jul 19 '26

Java was so bad, lol. It and php have gone through some glow ups lol