tags:

views:

117

answers:

3

I'm using the MVC pattern to design some data analysis software (in python). I'm not sure whether some functions should go in the model or the controller.

The way I've designed it, the user supplies the program a configuration file which contains the parameters for analysis. The program parses this file to find out what data files to look at and what kinds of calculations to do.

  • Should the function(s) that do this config file parsing be in the model or the controller?
  • Is there a standard way to organize things in python when using MVC? I've made the model, controller, and view into separate classes. The controller class contains instances of the model and view classes.
  • What kind of communication should there be between the model and the view? The way I'm structuring things is so that the controller takes stuff from the model and passes it to the view. The two only communicate through the controller.
+2  A: 

The model should be your entity classes, or simply classes that model the problem domain you're working with. And the view anything basically having to do with how your user interacts with the system you're building. The controller marries the two.

mkelley33
The function interacting with the config file should not be in either the model or controller ideally, rather they would live in a directory more akin to "data_access" or the like. Then, your model might interact with the config via an object in the data_access app/namespace. In other words, the config handling should either live outside the model or be parsed by the model if that isn't an option.
mkelley33
A: 

On your first point, the parsing should go in the model if it's part of the model class; for instance if you have a Configuration model, then the functions to load up configuration belong in the Model. If it's more of a service (e.g. I'm going to import this file in, and then something else is going to do the mappings) then it should be in the Controller. Without knowing more details it's kind of hard to say but that's the general rule that I follow.

I'm not sure on your second point since I'm not familiar with Python but the typical approach is to separate out your folder structure into Models/Controllers/Views and such, however I'm only familiar with MVC as it relates to web applications so I might be off the mark since your program seems to be a desktop app.

Your third point is exactly right. The model should not talk to the view; the controller communicates to the model and retrieves the information the View needs, and gives the view just that. I guess in essence the view might be working with the Model, but it doesn't know anything about the model (e.g. if it comes from a database, configuration file, xml, whatever)

Wayne M
A: 

to put it simply, model is your data part (the database) and view is your design part (html, css, js, etc) while a controller is contract between the model and view :)

Sarfraz