What is the right MVC diagram for a web application?

前端 未结 7 2135
情书的邮戳
情书的邮戳 2021-01-30 02:08

Which MVC diagram is correct? Each have different arrows...

Diagram 1

7条回答
  •  甜味超标
    2021-01-30 03:09

    They all are.

    MVC is a vague pattern.

    My view on MVC is that :

    Controller

    Object has a collection of models and has methods for viewing and editing the models. It talks to Models and returns instances of Views with models applied on them.

    View

    Has the definition of a model attached to it and is just a set of functionality to display a specific model.

    Model

    Encapsulates data. Has methods for returning state and changing state.

    //Controller
    import Views
    
    class Controller
      private Models
    
    //View
    import Model
    
    class View
    
    //Model
    class Model
    

    A Model doesn't need to know anything about the View / Controller. A View needs to know the definition of a Model. A controller needs to own Models and needs to know definitions of Views.

    You can couple them more tightly, that is optional.

提交回复
热议问题