Search code examples
javadesign-patternsinterfacepacman

Probable overuse of java interfaces in my implementation of Ms. Pac-Man


I have been a Java programmer for the last 6 years, and since the beginning of this year I got interested in game programming. So, I thought it was a good idea to start with a popular game and I implemented the game Ms. Pac-Man in Java. I can say that my implementation looks about 90% similar to the original game, and I tried to used as much design patterns and best practices as possible, since this was just a personal project to learn to code basic 2D games.

Now that I finished the coding, I realized that I have 19 interfaces and just 17 classes! So I start wondering if I might be overusing interfaces.

Here is an example of a few classes/interfaces that I use:

Class - FullGame (implements FullGameInterface and FullGameObservable)

Class - View1 (implements FullGameObserver)

Interface - FullGameInterface (basic functionality methods: resume, pause, play, etc.)

Interface - FullGameObservable (allows views to be registered for update notification)

Interface - FullGameObserver (implemented by the 2 different views of the game to receive notifications)

Am I overusing interfaces?

What is your opinion?


Solution

  • Interfaces are good. It's not a problem to have a lot of them.

    Particularly if you've only implemented your first game. If you re-used the code base to build more games, you would probably end up with more polymorphism, because you'd be re-using the interfaces. But at this point, if it's the case that there are more methods in the implementations than in the interfaces, then the interfaces are serving a purpose--they're hiding implementation details from the clients, who are thereby forced to conform to the interface, enabling the polymorphism that is the real benefit of OO.