需要模型-视图-演示者澄清

发布于 2024-10-19 10:02:12 字数 808 浏览 0 评论 0原文

我需要一些有关 MVP 中不同组件交互的指导。

例如,我有一个用于管理医院数据的应用程序。因此,我们假设 UI 有一个耐心的编辑器。现在,据我了解 MVP,我将创建一个带有 PatientViewPatientModelPatientPresenter。现在,PatientView 将显示用户界面,当它发生更改时,将其委托给 PatientPresenter,然后由后者更新 PatientModel。当模型发生变化时,应该通知presenter还是直接通知view然后更新view?

现在让我们假设有一个父组件,一个PatientManager,它显示患者的概述,允许搜索患者等等。现在我可以为这个组件做另一个三元组,但它如何与 PatientModel/View/Presenter 交互?

如果 PatientManagerMode 有多个 PatientModel 对我来说是有意义的,如果 PatientManagerView 拥有一个实例,对我来说也有意义PatientView 作为子控件,但是为什么 PatientManagerPresenter 应该保存 PatientPresenter 的实例?如果不应该,谁应该?

那么,如果我双击 PatientManager 中的某些内容以便编辑患者,到底会发生什么情况呢?

I need some guidance with the interaction of different components in MVP.

For example, I have an application to manage data in a hospital. So let's assume the UI has a patient editor. Now as far as I understand MVP, I would create a PatientPresenter with a PatientView and a PatientModel. Now the PatientView would show the user interface and when it changes delegate it to PatientPresenter which would then update PatientModel. When the model changes, should it inform the presenter or directly inform the view which then updates the view?

Now let us assume there's a parent component, a PatientManager which shows an overview of patients, allows to search the patients and so on. Now I could do another triad for this component, but how would it interact with the PatientModel/View/Presenter?

It would make sense to me if the PatientManagerMode would have several PatientModels and it would also make sense to me if the PatientManagerView holds an instance of the PatientView as a childcontrol, however why should the PatientManagerPresenter hold an instance of the PatientPresenter? And if it shouldn't, who should?

So what exactly should happen if I double click something in the PatientManager so that I can edit the patient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2024-10-26 10:02:12

当模型发生变化时,是否应该
通知主持人或直接
通知视图然后更新
查看?

模型应通知演示者,然后演示者更新视图。

现在让我们假设有一个父母
组件,一个 PatientManager,其中
显示患者的概况,...但是
它将如何与
患者模型/视图/演示者?

我将它们视为处理患者管理的更大 UI 的子视图。在这种情况下,演示者将处理两者。负责填写患者经理并回应搜索。然后,当操作员选择患者时,视图会将其传递给呈现者。然后,当显示患者详细信息时,礼物将从模型中检索数据并填写患者详细信息。

我分层的方式就像这样

View Assembly/EXE/Package
演示程序集/DLL/包
命令汇编/DLL/包
Presenter Manager 程序集/DLL/包
模型组件/DLL/包

视图将实现在Presenter中找到的视图接口,例如IPatientManagerView和IPatientView,并向Presenter注册自己。这些实现将使用通过 Presenter Manager 公开的 Presenter 接口。例如 IPatientManager 和 IPatient

演示者将实现演示者管理器中的演示者接口,并在演示者管理器中注册自己。它可以是一个同时实现 IPatientManager 和 IPatient 或两个的类。当它需要执行 UI 相关或模型相关的操作时,它会执行命令中的命令。该命令将使用模型和/或演示者接口来执行操作。

抚养一个病人看起来就像这样。

您有一个实现 IPatientManagerView 的对话框,并注册到实现 IPatientManager 的类。

  • 用户点击搜索
  • 搜索调用的搜索方法
    IPatientManager
  • 该类实现 IPatientManager
    使用 IPatientManagerView 来检索
    搜索参数。
  • 然后设置并执行搜索
    检索列表的命令
    病人。
  • 搜索命令调用 ListPatients
    在 IPatientManager
  • 类上实现
    IPatientManager使用方法
    IPatientManagerView 的清除和填充
    出病人名单。

  • 用户双击患者
  • 对话框实施
    IPatientManagerView 将调用
    实现 IPatientManager 的类
    表明特定患者是
    待查看。
  • 该类实现
    IPatientManager 检索
    所需患者的信息
    从对话框中查看执行
    IPatientManageView
  • IPatientManager 然后设置并
    执行命令查看
    病人。
  • 该命令检索所有
    来自模型的患者信息
    并调用 ViewPatient 方法
    类实现
    IPatientManager
  • 然后 IPatientManager 检索
    实现 IPatient 的类。
  • 将患者信息传递至
    IPatients 并告诉它显示
    本身。然后 IPatient 检索
    已注册的 IPatientView
    它。
  • 与患者一起填写
    使用 IPatientView 获取数据,然后
    告诉 IPatientView 显示自身。

使用此方案,您可以通过更改实现各种视图界面的内容来从根本上更改 UI。您还可以通过创建实现 View 接口的虚拟类来轻松地进行自动化测试。另外,为了将来的维护,每个交互都通过接口明确记录。

When the model changes, should it
inform the presenter or directly
inform the view which then updates the
view?

The model should inform the presenter which then updates the view.

Now let us assume there's a parent
component, a PatientManager which
shows an overview of patients, ... but
how would it interact with the
PatientModel/View/Presenter?

I would consider them as subviews of a larger UI that deals with managing Patients. In this case the Presenter would handle both. Taking responsibility for filling out the Patient Manager and responding to searches. Then when the operator selects a patient the view passes that to the presents. Then when the patient details are brought out the presents retrieves the data from the model and fill out the patient details.

The way I would layer it is like this

View Assembly/EXE/Package
Presenter Assembly/DLL/Package
Commands Assembly/DLL/Package
Presenter Manager Assembly/DLL/Package
Model Assembly/DLL/Package

The View would implement the view interfaces found in the Presenter say IPatientManagerView and IPatientView and registers themselves with the Presenter. The implementations would use the Presenter Interfaces exposed through Presenter Manager. For example IPatientManager and IPatient

The Presenters would implement the Presenter Interface found in the Presenter Manager and register themselves in the Presenter Manager. It could be one class that implements both IPatientManager and IPatient or two. When it needs to perform an action either UI related or Model related it executes a command found in Commands. The command would use the Model and/or the Presenter Interfaces to perform the action.

To bring up a patient would look something like this.

You have a dialog that implements IPatientManagerView and is registered with a class that implements IPatientManager.

  • User clicks Search
  • Search calls the Search Method of
    IPatientManager
  • The class implement IPatientManager
    uses IPatientManagerView to retrieves
    the search parameters.
  • Then setups up and execute the Search
    Command which retrieves a list of
    patient.
  • The Search Command calls ListPatients
    on IPatientManager
  • The class implementing
    IPatientManager uses a method
    IPatientManagerView to clear and fill
    out the list of patient.

  • User Double Clicks on a Patient
  • The Dialog implement
    IPatientManagerView will call the
    class implementing IPatientManager
    indicating that a specific patient is
    to be view.
  • The class implementing
    IPatientManager retrieves the
    information about the patient needed
    to view from the dialog implementing
    IPatientManageView
  • IPatientManager then setups and
    executes a command to view the
    Patient.
  • The command retrieves all the
    patient's information from the Model
    and calls the ViewPatient Method on
    the class implementing
    IPatientManager
  • IPatientManager then retrieves the
    class implementing IPatient.
  • Passes the patient information to
    IPatients and tells it to display
    itself. IPatient then retrieves the
    IPatientView that is registered with
    it.
  • Fill it out with with the patient
    data using IPatientView and then
    tells IPatientView to display itself.

With this scheme you can radically change the UI by changing what implements the various view interfaces. You can also easily right automated test by creating dummy classes that implement the View interfaces. Plus for future maintenance every interaction is explicitly documented through the interfaces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文