douyujun0152 2017-02-07 00:59
浏览 72
已采纳

这真的是MVC设计模式还是应该称之为其他?

This is a question about theory, so there is no need for code snippets.

I built a router that, as a typical router does, dispatches a controller based on the URL. The workflow is something like this:

  1. Router dispatches controller and instantiates it
  2. Controller renders a view
  3. User interacts with the view
  4. Controller updates model based on user interaction
  5. Model returns the new state of the data to the controller
  6. Controller updates the view based on new data

So basically, the controller is the starting point and the link between the model and view. The model and view never directly interact with each other. The controller is the workhorse and has most of the code.

Now, that is all good and I get it. The confusion comes when I read articles about MVC design patterns and realize what they describe is not what I just described above. It seems like, in the pattern you start at the view. The view talks directly to the model and the controller accepts user interaction to update the model.

So, what I'm doing may involve models, views and controllers, but its not strictly the MVC design pattern. I did read one article where they called what I first described as CAV, controller action view.

My question is, what is it that I'm describing? I don't want to keep referring to it as MVC if its not actually MVC. From what I read true MVC was birthed in the 70's. Things have changed since then. Perhaps what I'm doing is some evolved version of MVC, but not MVC in its strict form. Is there another name for it so I can stop confusing myself, and others, by calling it MVC?

  • 写回答

2条回答 默认 最新

  • duanfan1869 2017-02-07 01:56
    关注

    I think its language (technology) dependent. You tagged your question with the php tag, so I suppose you're developing applications using this language. In a classic PHP application, the view can't get updates from the model (in fact, this more related to the PHP language being executed only on the server).

    First, the entire application is launched for each request and is terminated when all the response has been sent. So, the router is called for each request.

    Then, the router execute the controller which have to handle the request (according to routing rules).

    The request being for reading or writing does not modify this behavior.

    If you want to allow the view to ask for data modification approval to your controller, you may need to use some client-side programming language (Javascript). So, you may use a REST API to handle communication between the model and the view.

    To answer your question, I think you can't implements a pure MVC design pattern on a client-server model without using a programming language on the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么