“Hello World” in MVC Pattern

后端 未结 5 1438
挽巷
挽巷 2021-01-29 19:18

In an interview for some company, I was asked this question.

What design patterns do you know...then I was told to write simplest \"hello world\" application based on MV

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 19:43

    I think you're kind of missing the point here.

    MVC is a pattern you'd use for designing an application. I think at the minimum you'd expect to be able to change the model, and see the change reflected in the view.

    You'd typically have an object to represent the model, a different object to represent the "view" (which would probably mediate between the model and the HTML objects that you're using as the view) and a controller, which would take inputs from your HTML objects and update the model.

    So you change an edit field, the edit field tells the controller, the controller updates the model, the model fires events that the controller uses to update any other view components that depend on this data.

    It'd be a few more lines to implement a "hello world" version, but I think this is what I'd be looking for from an interview question like this.

提交回复
热议问题