MVC on the command line

后端 未结 4 1345
后悔当初
后悔当初 2021-02-05 19:58

I am looking into the MVC from a Command line point of view (not web and no framework).. nice and simple. the only thing that confuses me is the View part of this? (well it may

4条回答
  •  无人共我
    2021-02-05 20:21

    I'm not sure to get how you transposed the concept of view on the command line but I'll try to answer.

    My person controller could pass a person object to the EditPeronDetails view, however how does my view edit the person if it cannot access its setters, how can I edit the person?

    It doesn't, the controller does. The view only "captures" new values and actions and send them to the controller which handles them and updates the model.

    Also does the view class only do one thing? ie can I have a Person View, which has methods for Create, View, Delete, edit the person

    A view can do multiple things. For example, a same form could be used to create, read and update a domain object (by create and edit, I mean capturing values and sending them to the controller). This is actually a very common pattern. But as I said, it's not the view that performs the logic, it's the controller that does.

    So, to answer your question, I guess we can imagine having dedicated methods on the Person View to capture the user input and to handle communication with the controller, but not for the CRUD logic (I'm really wondering how you handle interactions with the user on the command line, it doesn't seem really handy for a CRUD application).

提交回复
热议问题