0

I try to create a simple game in Java with the Model-View-Controller pattern.

My currently implementation is that

Model

  • Country
  • Timer
    • Observable
  • Money
    • Observable
    • contains Map < Country,Integer>
    • increases Money on update from Timer

Controller

  • Server
    • adds Gui-Observer to Money and Timer
    • static list of Countries

View

  • ServerGui

    • starts Server
    • gets Money and Timer updates
    • add itself to Server for Observer updates
    • open PlayerView
  • PlayerGui

    • has some countries
    • displays current time and money for each country

ScreenShot:

screenshot of the Game World

Is my current implementation a correct MVC implementation?

Is there something that you would change?

Jongware
  • 22,200
  • 8
  • 54
  • 100
user547995
  • 2,036
  • 8
  • 33
  • 62

1 Answers1

1

This is just as much an art as it is a science, but one thing that sticks out to me is this: why does your model contain a Timer? Shouldn't that be in the controller? What if you wanted to change the model to support, say, stepping through the simulation?

But you should stick with whatever design fits best in your head. The whole point of patterns is to make code more maintainable, and the best way to make code more maintainable is to design it in a way that makes sense to the people who have to work on it. Since that's you, you should do whatever makes sense to you, not strangers on the internet.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • But part of the idea of patterns is to encourage standardisation among implementations. That way, new developers can come along, recognise the pattern and instantly have a good idea of what the code is doing. So while your advice is good, a developer definitely should keep new contributors in mind. – christopher Jan 09 '14 at 15:15
  • @Chris Agreed. I just don't know how much value there is to novices stressing out over strictly adhering to patterns (especially with the above, which seems reasonable enough), when they're still learning the basics. – Kevin Workman Jan 09 '14 at 15:17
  • 100% agreed. My comment was more for the benefit of people looking to implement their patterns in a production/commercial environment. Plus it's always good to make people aware of the potential challenges they might face later on, at an early stage. – christopher Jan 09 '14 at 16:01