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 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错