Sign in to follow this  

API Question

Recommended Posts

Hiya, The design for my next game engine has interfaces such as IFileStream, IInput, ITimer, etc. as you would expect. For example, the Input interface has an accessor GetDeltaMouseWheel(). If the input is not initialized, however, this method can't return a meaningful value. I'm not sure whether to just return 0 or false or whatever, or whether to go down the COM route and return an error code. I'll try and make it a bit clearer with some (pseudo)code.
class IInput

    // first method
    long GetDeltaMouseWheel() const = 0;

    // second method
    enum ERROR {
        // etc... };

    ERROR GetDeltaMouse( long &lDelta ) const = 0;

As far as I can see, the first method is easier to use, but the second method can potentially return more information about why the call failed to the client application. What do you prefer to use? I know it's only a small detail, but I prefer to have as much planned out as is feasible before I dive in. Many thanks for any replies [smile]

Share this post

Link to post
Share on other sites
Why would the input not be initialised? That should be done when you instantiate an input object, and any failure to initialise would therefore be handled at that point well before an attempt was made to call any of your input polling/processing methods.

Is it going to make any difference to the calling code why you're unable to get input? If it is, return a meaningful value of some description. If it isn't, just return null or some other sentinal value to indicate an error. Personally I would probably be inclined to return null and set an error flag elsewhere than can be checked if desired.

Share this post

Link to post
Share on other sites
Good point. I want to keep the interfaces consistent, so the methods that aren't accessors can just return true/false and set an error code.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this