Question

During a recent phone screen I was asked to describe the "Factory Pattern". I asked if the screener meant "Factory Method" or "Abstract Factory". He said, "No, just the Factory Pattern".

I don't know what the Factory Pattern is except in the context of the aforementioned GoF patterns. I've been researching this since the phone screen, but nothing I've found indicates that there is a third "just" Factory Pattern. The closest I came was this question, but still that seems to just distinguish Factory Method from Abstract Factory.

Is there a distinct third factory design pattern? If not, does "Factory Pattern" always just mean "Factory Method"?

Was it helpful?

Solution

To the best of my knowledge, no design pattern library discusses anything called a "factory pattern". There is a general term "factory", which simply refers to an object that creates other objects. But if you're talking about the documented names for patterns, you need to be specific - after all, part of the point of design patterns is for communication, so everyone should be using the same terms.

Some sites do discuss different types of specific factories, such as Abstract Factory and Factory Method together. OODesign.com does this, and C2 wiki has a page called "FactoryPattern" that links to the pages for Abstract Factory and Factory Method.

OTHER TIPS

Factory pattern refers to the general principle of having an entity (be it a class, an abstract class, an interface or a method) which knows how to create instances of other entities (usually objects implementing an interface of interest) on behalf of a caller so that the caller does not have to know how to create them.

Both abstract factories and factory methods are specializations of the factory pattern. So, I think the interviewer was a bit of a stickler. Or perhaps they failed to communicate to you that all they wanted from you was to describe the general principle, not caring about any specifics. Or perhaps they were suspicious as to whether you understand the general principle and you have not just memorized the definitions of certain terms.

Licensed under: CC-BY-SA with attribution
scroll top