It's pretty common to use closures as factories in ZF2, although using a factory class is also an option (with more overhead).  Generally I'd use a factory class if the construction was complex, or if I thought that it was likely that people would want to override the object construction logic whilst still calling on the original logic.

For example, a factory class, WidgetFactory, could be overridden by extending WidgetFactory in BlueWidgetFactory and then setting BlueWidgetFactory as the class in the services / controller config files.

    class WidgetFactory implements FactoryInterface
    {
        public function createService(ServiceLocatorInterface $serviceLocator)
        {
            $widget = new Widget();

            // A lot of very complex set up of the widget.

            return $widget;
        }
    }

    class BlueWidgetFactory extends WidgetFactory
    {
        public function createService(ServiceLocatorInterface $serviceLocator)
        {
            $widget = parent::createService($serviceLocator);
            $widget->setColour(new Colour('blue'));
            return $widget;
        }
    }


In this instance, without the factory class (if we'd used a closure) the user would have had to copy and paste "a lot of very complex set up of the widget" into a new closure.  Using the factory class, they can just call the parent before making specific changes (setting colour dependency) as shown above.

What is the answer in this case?  Debatable - adding a factory class will add overhead, but it does increase flexibility.  But the closure is not complex so perhaps we don't need a factory class.  Discuss... ;-)