O
Oystein Haare
I'm thinking about sort of a factory-system where the factories get
instanciated on program start (through a global object in the .cpp file),
and registers themselves with a singelton.
Is it a good idea to create global objects like that?
Maybe it won't work at all?
code:
class AbstractFactory { ...};
class AbstractProduct { ...};
class Manager {
public:
static *Manager instance();
registerFactory(AbstractFactory *factory);
};
....
// Header:
class ConcreteProduct : public AbstractProduct { ... };
class ConcreteFactory {
public:
ConcreteFactory()
{
Manager::instance()->registerFactory(this);
}
};
// Cpp:
ConcreteFactory factory; // instanciate a factory object
// (is this a bad idea??)
// implementation
instanciated on program start (through a global object in the .cpp file),
and registers themselves with a singelton.
Is it a good idea to create global objects like that?
Maybe it won't work at all?
code:
class AbstractFactory { ...};
class AbstractProduct { ...};
class Manager {
public:
static *Manager instance();
registerFactory(AbstractFactory *factory);
};
....
// Header:
class ConcreteProduct : public AbstractProduct { ... };
class ConcreteFactory {
public:
ConcreteFactory()
{
Manager::instance()->registerFactory(this);
}
};
// Cpp:
ConcreteFactory factory; // instanciate a factory object
// (is this a bad idea??)
// implementation