felixwatts wrote:IEventHandler is a simple interface I made up that has one method:
void onEvent(int eventType, Object arg)
I'm from a C# background where the convention is to begin interface names with an 'I'. Maybe there is already a similar interface in the java api which you could use instead. Basically any object can implement IEventHandler by just having that one method. Then that object, whatever it is, can be used to handle event s of the model.
The reason I'm using that interface is so that the model has a way to tell the outside world when something important has happened inside it, without it having to know anything about the outside world. I could have passed the Game object into the constructor of the Model, then the model could still have called onEvent on the Game object as it does now. But that would have introduced a dependency on the Game object, which is specfically a LibGDX thing. If later I wanted to port to another framework I would have to change my model to remove the reference to Game. By using a simple interface then I don't have to change the model to port to a different framework, all I have to do is implement one method in my new framework (onEvent) and pass that into the model instead. Interfaces are brilliant!
Users browsing this forum: No registered users and 5 guests