1

I am working on a text adventure with a gui console. I have it setup now so that the user enters text using the view (for example "examine key", "look around", etc.) Then using listeners this data is then sent from the view to the controller. Once the text is sent to the controller, I am sort of stuck. Following the MVC model, should I be sending the text from the controller to the model and have the model parse it and figure out what to do with it, or should the model simply be a sort of "storage" where the controller parses the data, and just tells the model basic commands? For example, if "pickup key" is sent to the controller, should the controller be telling the model to simply add the key to the players inventory and remove it from the room, or should the entire text be sent to the model to be handled?

I understand this is a really basic MVC question, I am just sort of confused about the specific roles of each part of MVC even after reading quite a bit about it and looking at some flowcharts explaining the model.

user2249516
  • 281
  • 2
  • 5
  • 12
  • 1
    The model should have the brains of the program. Try to think what would be invariant about this program were it to be a text based game, a Swing GUI, a smart-phone game, an internet-based game. That which would be unchanged for all these situations would likely be in the model. – Hovercraft Full Of Eels Nov 15 '13 at 17:14
  • @HovercraftFullOfEels So the controller just passes the data between the model and the view but never actually touches the data? It is just a layer in between the two to allow each to be tested separately and/or to make expansion easier? – user2249516 Nov 15 '13 at 17:20
  • Well it depends, sometimes the model can't do all things, for instance, if an action depends on an old action, I believe the class Action can't have all the logic, or if an action depends on on an action thrown on network by another player: network code won't be in model. – zenbeni Nov 15 '13 at 17:36
  • @HovercraftFullOfEels is correct; as discussed [here](http://stackoverflow.com/a/3072979/230513), Swing MVC is model-centric. – trashgod Nov 15 '13 at 20:50

2 Answers2

0

There are many way to answer this question. This answer might be not upto the mark,Its just my understanding.

I think create a model that represent an entity along with operations. Then there will be controller or call as Request Handler that accept the request along with data then decide what operation to use from Model to successfully handle the request.

Since data management is responsibility of model, so you can have another layer to deal with storage and use it with model or handle storage in model itself.

palash140
  • 673
  • 6
  • 13
-3

The model is the persistent storage i.e. database. The controller process's the information from the user to the model The view shows the information from the model to the user and accepts input from the use.

  • 2
    The model isn't necessarily persistent. – jamesSampica Nov 15 '13 at 17:19
  • I should have prefaced with a very basic description of the elements. True that the model does not have to be persistent and I did not include anything about View Models either. Just a very basic explanation of the parts of MVC – user2949011 Nov 15 '13 at 17:21
  • Please, learn something about the subject, before starting to "answer" questions. – tereško Nov 17 '13 at 06:00