MVC - Separation of Concerns

后端 未结 3 882
情歌与酒
情歌与酒 2021-02-04 13:04

I\'m a newbie. I want to ask about the MVC model for separation of concerns. I have read up a few MVC tutorials but I don\'t yet have a full understanding of the roles of each o

3条回答
  •  猫巷女王i
    2021-02-04 13:43

    Nice question, this is subjective and there are many solutions, it comes down to the context I think and the preferences of the individual.

    With ASP.Net implementation of MVC alot of people talk about the Model being more of a ViewModel than a Model as in some other frameworks (somewhat of a DTO). This in mind and looking at the Controller as just a coordinator of the flow of the application, it would not be wrong to generate the lists in an additional layer accessed via a service of some type. You would make a request to that service for a set of ViewModels which meet a specified set of criteria and let that extra layer worry about the way in which those lists are generated from that set of criteria. This way all the controller needs to know about is passing some criteria to the service and providing the view with a set of models (viewmodels) to display, the view is free of making any decisions about what to do with the data it has been provided, and the models are nice and lightweight.

    Hope this explanation makes sense, and I'm open to criticism if people don't agree...

提交回复
热议问题