Is MVC a good design pattern for a GAE app?
my GAE app is currently setup with the following filenames
- main.py (2 main models and logic for creating and updating the models)
- i18n.py (user interface logic how to view objects with i18n)
- reports.py (cron-based reporting script)
I think the names are clear enough but I am considering to follow a model-view-controller pattern so renaming these three files to model.py view.py controller.py is what I consider an option to follow a more standardized convention. Do you agree that this type of modularlization towards a MVC convention is the reasonable way to go in this case, do you need more information what's my app: I've got a lot of code that's functional towards the user which is code I feel is right to refactor in a way that follows a generally accepted design pattern such as MVC, publisher-subscriber, factory and more. In this case I think the MVC design pattern is appropriate. Do you agree or suggest other开发者_如何学Go code and data treatment? Thanks for any comments and discussion.
You are miss-understanding MVC. Model, View, Controler is in three parts.
Model - contains the business logic. Knows how to read/write to the database. View - Contains the display logic. Knows how to fetch data from model and display it to the user. Controller - understands user gestures, loads/finds the correct model and view and tells them what to do.
(In a web environment, the view should unpack the data from POSTs, and the model should validate it).
You have M and C in main.py, and propably V in i18n.py and main.py (hard to tell). The cron-run reports are external to MVC.
Just renaming the files will not gain you anything, but will confuse any other maintainer.
If you are proposing to make significant changes to your code without a test suit to proptect you from introducing errors, then I must point out that such an action is not wise.
精彩评论