Archived

This topic is now archived and is closed to further replies.

paulbgoode

filling one interface with more DLLs

Recommended Posts

i want to put my engine in several run-time loaded DLLs, but expose it to the rest of the program as a single interface. something like this:
  
class IEngine {
    virtual void renderFunc() {};
    virtual void soundFunc() {};
};

class CRender : public IEngine {
    void renderFunc();
};

class CSound : public IEngine {
    void soundFunc();
};
  
Of course, this does not work. But what would be a clean solution to do something like this? Letting CSound inherit from CRender would be stupid, and making an extra class that calls functions from CRender and CSound would add a useless level of indirection. Any ideas?

Share this post


Link to post
Share on other sites
I assume your are referring to a typical OOP design in C++ and not a COM interface-based OOP design.

What is the relationship of Engine, Render, and Sound?

Kuphryn

Share this post


Link to post
Share on other sites
I''d suggest a single ''Engine'' class that has pointers to all the other engines stored on the free store. This may seem pointless, but will give you the organization you''re looking for with still being able to have seperate DLLs for each section. It also allows you to isolate and encapsulate code you don''t want most users to have access to. As well it would make it easier for different version support as well.

Pat

Share this post


Link to post
Share on other sites
isolation and encapsulation is indeed what i am looking for. i am converting C code to C++, and this is what i'd do in C:

    
typedef struct {
void (*renderFunc)();
void (*soundFunc)();
} IEngine;

//in render.dll:

void setInterface(IEngine *engine)
{
engine->renderFunc = renderFunc;
}

//in sound.dll:

void setInterface(IEngine *engine)
{
engine->soundFunc = soundFunc;
}

so in C++ i would want to update the vtable of IEngine with functions from different DLLs. what patindahat says would result in something like this: engine->render->renderFunc();, or maybe you could inline a wrapper in the IEngine definition.
void renderFunc() {engine->renderFunc()}. hmm. maybe what i want is just bad coding practice..


[edited by - paulbgoode on May 8, 2003 3:01:14 PM]

Share this post


Link to post
Share on other sites