GUI设计模式,MVP,选项卡控件
我有一个应用程序,其窗口类似于下面的窗口。
替代文本 http://a.imageshack.us/img137/7481/screenshotxh.jpg< /a>
这里的要求是,当用户单击保存按钮时,所有内容都必须保存。 “保存”和“重置”按钮对于所有选项卡都是“通用”的。因此,当选择“个人信息”选项卡并单击“保存”时,程序还应该保存在“朋友”选项卡中所做的更改以及在“工作历史记录”选项卡中所做的更改。
该应用程序已具有以下代码,我想保留此代码:
-PersonalInformationView 、 PersonalInformationPresenter、PersonalInformationModel
-FriendsView、FriendsPresenter、FriendsModel
-EmploymentHistoryView、EmploymentHistoryPresenter、EmploymentHistoryModel
每个演示者都有一个 Save 方法。
问题是考虑到我想保留我已有的代码,什么是一个好的设计模式。另外,我希望这个窗口也有模型、视图、演示者。或者也许我应该稍微改一下我的问题:在编程 MVP 时包含“子视图”、“子演示者”的最佳方式是什么?
问候, 麦德塞布
I have an application that has a window similar to the one bellow .
alt text http://a.imageshack.us/img137/7481/screenshotxh.jpg
The requirement here is that when the user clicks the Save button everything has to get saved. The "Save" and "Reset" buttons are "common" to all tabs. Hence, when the "Personal Information" tab is selected and "Save" is clicked the program should also save changes made in the "Friends" tab and changes made in the "Employment History" tab.
The app already has code for the following and I want to keep this code:
-PersonalInformationView , PersonalInformationPresenter, PersonalInformationModel
-FriendsView, FriendsPresenter, FriendsModel
-EmploymentHistoryView, EmploymentHistoryPresenter, EmploymentHistoryModel
Each presenter has a Save method.
The question is what would be a good design pattern to use taking into consideration that I want to keep the code I already have. Also, I want this window to have model, view, presenter as well. Or maybe I should rephrase my question a bit: what's the best way of including "sub-views", "sub-presenters" when programming MVP ?
Regards,
MadSeb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我个人建议创建一个抽象接口、ISaveable 或 osmething,并确保每个演示者都实现此接口,而不是将每个演示者作为 ISaveable 对象进行遍历并保存每个演示者。
I personally would suggest making an abstract interface, ISaveable, or osmething and ensure that each of the presenters implement this, than go through each presenter as an object of ISaveable and save each one.
我会让你的新演示者将你的子演示者作为构造函数参数,例如:
当然,如果你的演示者之间有一个公共接口,则可以像这样简化(并使其更具可扩展性):
编辑:< /强>
调用代码将是这样的:
希望这有一些启发/帮助:)
I would make your new presenter take in your sub presenters as constructor arguments, something like:
Of course, if your presenters had a common interface between them, this could be simplified (and made more extendable) like so:
Edit:
Calling code would be something like this:
Hope that is of some inpsiration/help :)
我的建议是使用 save 方法创建 ISaveableView。
您的每个视图都将实现该接口。
我猜测您的选项卡实现了您所描述的视图。当您单击保存按钮时,您可以将活动选项卡投射到 ISaveableView 并调用其保存方法
My suggestion is to create ISaveableView with save method.
Each of your views will implement the interface.
I am guessing that your tabs implements the views you've described. When you click the save button you can cast the active tab to ISaveableView and call its save method