本文介绍了C#类如何在MVP模式中进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我对MVP模式中未知的classen之间的沟通有疑问。 我得到的任务: 我必须使用MVP模式创建一个WindowsForms-Application,这意味着Presenter知道查看器(表单)和模型,但查看器和模型一无所知(对吗?)。 表格显示一个带有两个文本框的小公式(用于名字和姓氏,两个按钮) (用于保存名称并在富文本框中显示所有已保存的名称)和丰富的文本框。 现在用户必须填写他的名字并按下按钮用于将名称保存在列表中(通用列表,或字典,或其他什么,无关紧要)。 因此,演示者必须知道查看器上的某些更改(例如,单击了保存按钮,现在必须将字符串提供给演示者。) 我相信在这一点上你知道什么是goi在这个系统可以工作的代码中。 问题: 我不知道如何告知演示者他现在必须使用名称字符串,以便他可以将其保存在模型的列表中。因为Viewer不知道Presenter 我听说过Observer,删除或捕获具有给定参数的事件,这可以由演示者捕获。但是我不知道我应该使用哪个系统如何实现和使用oberver或代表等。 我用google搜索了3天而没有令人满意的结果。 ..... 我希望你们能帮助我解决这个问题:) 问候,ToShX 解决方案 Hi,I have a question about the communication between unkown classen in the MVP-Pattern.The task I got:I have to create a WindowsForms-Application with the MVP-Pattern, which means that the Presenter knows the Viewer (the Form) and the model, but the Viewer and the Model know nothing (right?).The Form shows a small formular with two textboxes (for firstname and lastname, two buttons (for saving the name and for showing all saved names in a rich textbox) and a rich textbox.Now the user have to fill in his name and press the button for saving the name in a list (generic list, or dictionary, or whatever, that doesn't matters).Therefore the Presenter must know WHEN something changes on the Viewer (e.g. saving button was clicked and now the strings must be given to the presenter).I'm sure at this point you know what's have to going on in the code that this system will work.The problem:I don't know how to inform the presenter that he must now take the name-strings so that he can save it in the list in the model. Because the Viewer doesn't know the PresenterI've heard something about Observer and delegets or catching events with given parameters, which can catched by the presenter. But I don't know which system I should use neither how to implement and use the oberver or delegates etc.I googled for just 3 days without a satisfying result......I hope you guys can help me to solve that problem :)Greetings, ToShX 解决方案 这篇关于C#类如何在MVP模式中进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 19:59