Say you have a class who\'s job it is to connect to a remote server. I want to abstract this class to provide two versions, one that connects through UDP and the other throu
I would use the curious recuring template pattern, aka Five Point Palm Exploding Alexandrescu Technique:
template
class Transmit
{
public:
void send(...)
{
_U.send(...)
};
private:
Underlying _U;
};
class Tcp
{
public:
void send(...) {};
};
class Udp
{
public:
void send(...) {};
};
There would probably be many more template parameters and sub classes but you get the idea, you can also use static methods.
By the way template code is generally more efficient but also much bigger.