1

I have a question about the MVC pattern. I am creating a maze game in JAVA with swing and I'm trying to use the MVC pattern with it. So far it goes well but I don't get the "rules" of MVC.

Let's say I have two models: one for creating a maze and the other one for the player.

The player get's it's location from the maze created in the maze model. You see, the player determines it's location from that maze and decides if it can move to a new location. This part I understand, But can my player model ask the maze model for the maze? or is it out of the question in MVC used in a java swing application? (interactions between models).

thanks!

1
  • See also this the example game cited here. Commented May 23, 2014 at 17:59

2 Answers 2

3

öhm, this is one aspect of MVC that many people discuss all the time. For ME it just means that you have the really stupid VIEW-Part which does nothing else than showing Data and taking request. This Requests are forwarded to the Controller, which does some stuff with them and then call the MODEL to do the real work. So from my point of View, you are totally fine when Models talk to each other. But to rreduce dependency and improve encapsulation, i let my models get the other needed Models over the appropriate Controller, so i can use dependency Injection.

I see the COntrollers in my MVC apps as some kind of switchboard, which "regulate the traffic" and provide a place where you can call from inside the building to get a line to some co-worker, and from the outside you have to talk to the secretary.

I know other will say this is WRONG/RIGHT, but for me it works, even in teams.

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

Comments

1

MVC. Models only model your data and access that data. Views only serve the data to the user. The controller is like a conductor, putting it all together. Whether a model can be made up of another model, which I think you are asking, yes, but it might not be the best in terms of how tightly coupled your objects are. Is a player made of a maze object or just a location? Your question appears to be more about OOP principles than one of MVC. Unless of course I am miss reading your question.

Comments

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.