class IInput
{
public:
// first method
long GetDeltaMouseWheel() const = 0;
// second method
enum ERROR {
ERR_OK,
ERR_NOTINITIALIZED
// 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]
API Question
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.
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.
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.
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.
I would consider using the first method and let the function throw an exception if necessary.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement