Lets assume I have an interface class like
class car {
public:
virtual void move(double x, double y) = 0;
// etc etc
};
and a lot of derived classes like
class model8556 : virtual public car {
private:
void move(double x, double y) {
// ...
}
// etc etc
};
and I choose the model via
car* myCar;
switch (foo) {
case 1: myCar = new model3434(); break;
case 2: myCar = new model8295(); break;
// etc
}
Is there a good way to hide the switch code and maybe move it to the car
class itself? I could wrap another class(?) around car
(or just move the switch code to a global function?), but I wonder if there is something more elegant.
Any help is appreciated.