   Interface Question
  Hiya,I'm having some trouble designing the parts of my game that use interfaces. The problem is that some game components need to use functions/data which are not declared in other interfaces, only in classes that derive from them. It's difficult to explain, so here's a simpler example:// mesh interface - this is what the client code usesclass IMesh;class Mesh : public IMesh{private:    ID3DXMesh *m_pMesh; // or whatever format the mesh is stored as - this    //shouldn't be exposed to the client};// renderer interface - this is what the client code usesclass IRenderer{public:    void Draw( const IMesh *pMesh ) = 0;};// renderer classclass Renderer : public IRenderer{public:    void Draw( const IMesh *pMesh )    {   // this is where the problem is - the DirectX mesh object is not   // exposed by the IMesh interface, but renderer needs it to draw...   // how can I get around this?    }private:    IDirect3DDevice9 *pDevice;};// usage would be something like this - only the inerfaces are usedvoid main(){    // use factory functions which return the 'concrete' classes    IRenderer *pRenderer = CreateRenderer();    IMesh = pRenderer->CreateMesh();    pRenderer->Draw( pMesh );}I guess I'm not sure how to keep the implementation hidden, whilst still having each class be able to access the data it needs.Are there any common ways around this, or perhaps is my design just wrong? I don't see how libraries which only publish interfaces can work.Any help or suggestions would be very much appreciated [smile]James   
  I think what you're asking for is something akin to the Bridge design pattern. Unfortunately the Bridge design pattern can be quite difficult to understand. Generally this involves working out what these implementation details that you require are, and moving those into the interface, instead of relying on low-level details.Ultimately though, if you know that wherever you'll have a Renderer, you'll have a Mesh, you can just cast it... do some sort of check first however. :)What you have is a bit of an edge case where you have parallel hierarchies that rely on each other to operate. Rendering is the canonical example of this because performance is tied closely to the implementation. But in 95% of other situations simple interfaces are typically sufficient for what you need to do and nothing requires the lower level details to operate.   