Have a interface
class abc { public: virtual int foo() = 0; ... } class concrete1: public abc { public: int foo() { .. } class concrete2 : public abc { public: int foo() { .. } }
Now in my main program I need to construct classes based upon a value of a variable
abc *a; if (var == 1) a = new concrete1(); else a = new concrete2();
Obviously I don’t want these two lines everywhere in the program (please note I have simplified here so that things are clear). What design pattern should I be using if there are any?
You are looking for http://en.wikipedia.org/wiki/Factory_method_pattern