M
/M
Hi!
As you know, one way to seperate platform dependent code from platform
_independent_ code is to create an abstract base class which acts as an
interface towards all platform independent code and implement platform
specific code in the sub classes. Since the platform (in most cases I
quess ) can't vary during the execution of a program, using virtual
functions to specify the interface seams a bit odd. I'm thinking about
using templates instead in something like the following way.
template<class Impl>
class GenericSocket
{
//Interface
private:
Impl m_impl;
};
class Win32Impl
{
};
class UNIXImpl
{
};
#if defined WIN32
typedef GenericSocket<Win32Imp> Socket;
....
#endif
One downside of this approach is that the interface that must be
implemented by an implementation class isn't specified (at least not
fully) through the interface of GenericSocket which it would be when
using an abstract base class instead.
Any thoughts on this matter? How do you do it?
Regards
M
As you know, one way to seperate platform dependent code from platform
_independent_ code is to create an abstract base class which acts as an
interface towards all platform independent code and implement platform
specific code in the sub classes. Since the platform (in most cases I
quess ) can't vary during the execution of a program, using virtual
functions to specify the interface seams a bit odd. I'm thinking about
using templates instead in something like the following way.
template<class Impl>
class GenericSocket
{
//Interface
private:
Impl m_impl;
};
class Win32Impl
{
};
class UNIXImpl
{
};
#if defined WIN32
typedef GenericSocket<Win32Imp> Socket;
....
#endif
One downside of this approach is that the interface that must be
implemented by an implementation class isn't specified (at least not
fully) through the interface of GenericSocket which it would be when
using an abstract base class instead.
Any thoughts on this matter? How do you do it?
Regards
M