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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.