Jump to content
  • Advertisement
Sign in to follow this  
MrRage

Class framework design

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I’m working on the networking aspect of my framework and I was wondering if this is a good application of templates or multiple inheritances. I never took a class that dealt with fundamental layout and design of a framework so I’m a little shaky at best when it comes to it. The SocketImpl class is a wrapper for a SocketEngine. This engine can be as complex as an asynchronous SSL socket or as simple blocking tcp socket, but the final implementation doesn’t need to know that. They all work though the same SocketImpl interface. So the question remains should this be implemented though a template design or though multiple inheritance using a virtual base class SocketImpl?
class MyClass : SocketImpl <SocketEngine> {
...
};

or 

class SocketImpl {
...
};

class SocketEngine : SocketImpl {
...
};
class MyClass : SocketEngine {
...
};


Share this post


Link to post
Share on other sites
Advertisement
You didn't provide enough information about the roles of each of the classes and the relationships between then in order for anyone to give you a good answer.

On the other hand, I doubt that the template solution is right. In additon to SocketEngine, what other classes might you use as a template parameter for your SocketImpl class?

Share this post


Link to post
Share on other sites
I know this is probably wrong but until I have a chance to sit down later and work it out this is what I'm thinking of.


namespace Network {
class SslSocketEngine {
onRead();
onWrite();

};

enum Family {
AF_INET,
AF_APPLETALK,
AF_INET6,
AF_IPX
};

enum Type {
SOCK_STREAM,
SOCK_DGRAM,
SOCK_RAW
};

/////////////////////////////////////////
// Used for program driven Socket implementations
template <int family, Family type>
class Socket {
connect();
bind();
accept();
recv();
send();
sendTo();
setBlocking();
close();
};

/////////////////////////////////////////
// Used for socket driven implementations
template <Socket socketType, typename SocketEngine = NULL>
class SocketImpl {
public:
void send() {
if(SocketEngine != NULL) {
SocketEngine
}
}
void recv();
virtual void onSend();
virtual void onRecv();
};
}

using namespace Network;
class Myclass : SocketImpl<Socket<AF_INET,SOCK_STREAM>> {
public:

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!