Factory Method and Cyclic Dependancy

Posted by metdos on Stack Overflow See other posts from Stack Overflow or by metdos
Published on 2010-05-06T13:11:27Z Indexed on 2010/05/06 13:18 UTC
Read the original article Hit count: 300

If I'm not wrong, because of its nature in factory method there is cyclic dependency:

Base class needs to know subclasses because it creates them, and subclasses need to know base class. Having cyclic dependency is bad programming practice, is not it?

Practically I implemented a factory, I have problem above, even I added

#ifndef MYCLASS_H
#define MYCLASS_H
#endif

I'm still getting

Compiler Error C2504 'class' : base class undefined

And this error disappers when I remove subclass include from base class header.

© Stack Overflow or respective owner

Related posts about c++

Related posts about factory-pattern