Is this crufty?

Posted by bobobobo on Stack Overflow See other posts from Stack Overflow or by bobobobo
Published on 2010-02-25T02:39:45Z Indexed on 2010/03/18 3:41 UTC
Read the original article Hit count: 252

Filed under:
|

I'm writing code like:

class Game
{
    int getMouseX()
    {
        return inputManager.getMouseX() ;
    }
} ;

I remember seeing code like this and hating it. One function passes off to another? What is this "pattern" (or, possibly, anti-pattern) called? I don't like it!

On the other hand, it saves exposing the InputManager to the user of the class... would that be a better choice? Or should Game simply not contain InputManager?

Edit

What about using multiple inheritance instead?

class Game : public InputManager, public Window
{
    // by virtue of inheriting InputManager and Window,
    // Game now has "acquired" the capabilities of
    // InputManager's public functions, without requiring delegate.
} ;

Have I not found a reasonably good use for multiple inheritance??

© Stack Overflow or respective owner

Related posts about cruft

Related posts about code-smell