I would like to get some opinions on this template class interface. Will I run
into problems deriving from type IOPolicy? Would Containment be a better
approach instead of inheritance? My goal is to have the ability to do something
like:
typedef TCPConnectionInfo<ThreadedPolicy> ThreadedTCPConnection;
and in another process use a non-threaded policy:
typedef TCPConnectionInfo<OtherPolicy> TCPConnection;
Here's the class declaration:
template <class IOPolicy>
class TCPConnectionInfo : public IOPolicy, public ConnectionImpl {
public:
TCPConnectionInfo(string url);
virtual ~TCPConnectionInfo();
virtual int Read(char* ,int );
virtual int Write();
virtual int Socket();
virtual bool Init();
virtual bool Open();
virtual void Close();
private:
IPaddress serverIP;
TCPsocket sock;
string inputURL;
};
My intention is to have a policy based design for the socket i\o. This way if
changes are needed for performance reasons the policy could be modified instead
of the whole class. ConnectionImpl is a pure abstract base class that forces
TCPConnectionInfo to implement a certain interface. IOPolicy is forced to
implement what will be expected by TCPConnectionInfo's implementation. I don't
know exactly how the implementation will look.
Best Regards,
Jim Smith