Should a factory function be in it's own class as a static member or in a namespace? Is there any difference between the two meaning I must use one when creating a class factory?
In my case, the classes produced by the factory are container objects with different memory structures backing them. Something like
template< typename T >
class Parent
{
virtual void myFunction() = 0;
// more virtual interface functions...
}
template< typename T >
class ChildA : public Parent< T >
{
virtual void myFunction() override;
}
template< typename T >
class ChildB : public Parent< T >
{
virtual void myFunction() override;
}
template< typename T >
Parent< T >* factory( PerformanceTraits traits );
I took a look at Namespace + functions versus static methods on a class and have also read what Scott Meyers has to say on this subject but I don't seem to be able to apply this to factory functions.
If I use a namespace I can write
Parent* obj = MyFactoryNamespace::factory< int >( traits );
compared to
Parent* obj = MyFactoryClass< int >::factory( traits );
if I use a templated factory class. Other than this being two ways to write the same thing are there technical differences?
Thanks.