需要模型-视图-演示者澄清
我需要一些有关 MVP 中不同组件交互的指导。
例如,我有一个用于管理医院数据的应用程序。因此,我们假设 UI 有一个耐心的编辑器。现在,据我了解 MVP,我将创建一个带有 PatientView
和 PatientModel
的 PatientPresenter
。现在,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 PatientModel
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型应通知演示者,然后演示者更新视图。
我将它们视为处理患者管理的更大 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
使用 IPatientManagerView 来检索
搜索参数。
检索列表的命令
病人。
在 IPatientManager
IPatientManager使用方法
IPatientManagerView 的清除和填充
出病人名单。
IPatientManagerView 将调用
实现 IPatientManager 的类
表明特定患者是
待查看。
IPatientManager 检索
所需患者的信息
从对话框中查看执行
IPatientManageView
执行命令查看
病人。
来自模型的患者信息
并调用 ViewPatient 方法
类实现
IPatientManager
实现 IPatient 的类。
IPatients 并告诉它显示
本身。然后 IPatient 检索
已注册的 IPatientView
它。
使用 IPatientView 获取数据,然后
告诉 IPatientView 显示自身。
使用此方案,您可以通过更改实现各种视图界面的内容来从根本上更改 UI。您还可以通过创建实现 View 接口的虚拟类来轻松地进行自动化测试。另外,为了将来的维护,每个交互都通过接口明确记录。
The model should inform the presenter which then updates the view.
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.
IPatientManager
uses IPatientManagerView to retrieves
the search parameters.
Command which retrieves a list of
patient.
on IPatientManager
IPatientManager uses a method
IPatientManagerView to clear and fill
out the list of patient.
IPatientManagerView will call the
class implementing IPatientManager
indicating that a specific patient is
to be view.
IPatientManager retrieves the
information about the patient needed
to view from the dialog implementing
IPatientManageView
executes a command to view the
Patient.
patient's information from the Model
and calls the ViewPatient Method on
the class implementing
IPatientManager
class implementing IPatient.
IPatients and tells it to display
itself. IPatient then retrieves the
IPatientView that is registered with
it.
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.