Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Factory classes

Name: Anonymous 2005-11-17 4:09

Can somebody explain what are factory classes good for? As in, "why all this shit"? I have the impression factory classes are yet another suit in the Emperor's wardrobe. To me, they always looked like some bored programmer who needs to keep his job and hates the KISS principle decided to make our lives worse.

Name: Anonymous 2005-11-17 7:32

They're an attempt to improve performance by avoiding instantiating new objects all the time. Rather than let the programmer keep one object and constantly change it all the time (which would defeat the point of OO as an abstraction) you hide it behind a factory class. So when you call fooFactory.newFoo() you're not actually getting a new instance, it's modifying an old one for you.

Yeah it's a lot of extra work. Which sucks. If the compiler would do it automagically that would rock. I've actually been thinking about this recently: how about a language in which all objects are immutable and the compiler created factory classes behind the scenes for optimisation? I think this could be a useful way to merge OOP and FP.

Also see flyweight programming.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List