Model View Controller Design pattern Code Example

后端 未结 4 476
北恋
北恋 2021-02-01 09:35

I was studying the Model-View-Controller design pattern and i understand the concept behind the pattern theorotically, but I wanted to get a peek at how one would actually put i

4条回答
  •  长情又很酷
    2021-02-01 10:10

    Code is the best approach to understand and learn Model View Controller:

    Here is a simple JS example (from Wiki)

    /** Model, View, Controller */
    var M = {}, V = {}, C = {};
    
    /** Model stores data */
    M.data = "hello world";
    
    /** View controls what to present */
    V.render = (M) => { alert(M.data); }
    
    /** Controller bridges View and Model */
    C.handleOnload = () => { V.render(M); }
    
    /** Controller on Windows OnLoad event */
    window.onload = C.handleOnload;
    

    Here is a detailed post in C/C++ Model-View-Controller Explained in C++

提交回复
热议问题