I'm facing maybe a non-problem with some C++ class design, mostly because I need to integrate a database into my system. I've got a base class that has some child classes. I find it redundant to have a member called type which is an enum which described the type of child it is. Example
enum FooTypes {
kFooTypeGeneric,
kFooTypeA,
kFooTypeB
};
class Foo {
public:
Foo(FooTypes type):type(type){}
FooTypes type;
};
class FooA : public Foo {
public:
FooA():Foo(kFooTypeA){}
};
class FooB : public Foo {
public:
FooB() :Foo(kFooTypeB) {}
};
The reason that I feel forced to maintain an enum is because owners of Foos want to store what they have created into a database table. If the system reboots, they should be able to look into their own table and say, "Oh yeah, I have a FooA that I need to initialize", and that can only really be done by setting a column called "FooType" to 1 in this case.
I'm just wondering if this way of giving child classes a type that is part of an enum that they then must know about is bad design. It seems redundant among other things.