Accuray Interview Question

Describe the Factory Pattern and a time when you used it.

Interview Answer

Anonymous

Aug 22, 2016

A programmer using the Factory pattern requests objects from a centralized Factory class instead of creating and initializing objects itself. This is useful for centralizing logic in some cases but is more often used for adding a layer of abstraction between the consumer of a class and the list of concrete classes that could fill the role. A project I worked on used the Factory pattern to deliver custom classes to consumer functions based on the customer number, so different customers could get different logic simply by changing the factory class instead of thousands of points across the code base.