Just do not use enumerations. They are not an OO construct, so JAVA did not exist at the beginning (unfortunately, the pressure was too great to add them).
Consider instead of such an enumeration:
enum Types { typeA, typeB };
this design, which does not need to be switched (another design without OO, in my opinion) and maps:
types.h
class Base; class BaseFactory { public: virtual Base* create() = 0; }; class Types { public:
Types.cpp
#include "Types.h" #include "Base.h" #include "TypeA.h" #include "TypeB.h" namespace { TypeAFactory typeAFactory; TypeBFactory typeAFactory; unsigned unique_id = 0; } Types Types::typeA(&typeAFactory, unique_id++); Types Types::typeA(&typeBFactory, unique_id++);
So your example (if you really need this function):
class Base { static Base * create(struct Databasevalues dbValues) { return dbValues.ObjectType.create(); } };
Missing parts should be easy to implement.
source share