0

This may be a silly question, but with my current searches I have found mostly information about the presentation of data and the interplay between the Presenter and the View, but very little about the Model and the Presenter.

Basically, say I have a C# application, and it opens a CSV file that is a 5 by 5 array of numbers. Now if I wanted to load that 5 by 5 CSV array into an array of ints, where is this handled in the grand scheme?

This is my current idea to follow MVP, but please correct me if I am wrong (or confirm that I'm right, if I manage to be).

  1. The user clicks a button to load the file.
  2. The View loads a showOpenDialog() for the user to select the file.
  3. After user clicks okay in that dialog, the View, sends an event to the presenter containing that filename.
  4. The presenter takes that filename, handles the file opening and parsing it into a 5 x 5 int array.
  5. The presenter then provides that int array to the Model through an event. The model then stores that array.
  6. The model gives an event saying that it's data has changed.
  7. The presenter listens and handles this event, putting that 5 x 5 int array into a DataTable.
  8. The presenter raises an event saying that it has a new DataTableready.
  9. The view listens and handles this event, and updates a dataGridView with the information provided by the DataTable.

My understanding of MVP gets murky at about step 5 there. Is that how it should go, or did I misinterpret what each component does in MVP?

4

1 回答 1

2

您在 MVP 中使用事件的方式很有趣。但是我通常没有遇到过。

根据我的经验,这是工作流程:

  1. 在视图中单击的按钮
  2. 查看显示对话框
  3. 在属性中查看存储文件名
  4. View 调用 Presenter 方法(例如 loadFile)
  5. Presenter 使用 View 接口从属性中检索文件名
  6. 演示者 a) 使用服务执行加载或 b) 加载文件本身
  7. 模型是通过 Service 或 Presenter 构建的
  8. 模型通过 loadFile 方法传回给视图
于 2013-02-19T01:30:11.750 回答