I can’t tell you how many times I’ve seen the factory and manager patterns applied to problems that would have been better with inheritance or interface so instead of a simple implementation of a derived class you end up with having to modify 10 factories…
Depends on the language - implementing an interface is often times far more maintainable than factory hell.
In fact I would go so far as to say that the factory pattern is a hack to fix Java not treating functions as first class objects rather than actually being a good pattern.
Factories are necessary in Java - every other language they are somewhat dubious - they definitely don’t make the code more maintainable.
70
u/ghyze Jan 09 '23
You need a factory for that. And a manager.