Model-view-presenter
模式描述
Model-View-Presenter (MVP) 是用户接口设计模式的一种,被广泛用于便捷自动化单元测试和在呈现逻辑中改良分离关注点(separation of concerns)。
- Model 定义用户接口所需要被显示的数据模型,一个模型包含着相关的业务逻辑。
- View 视图为呈现用户接口的终端,用以表现来自 Model 的数据,和用户命令路由再经过 Presenter 对事件处理后的数据。
- Presenter 包含着组件的事件处理,负责检索 Model 取得数据,和将取得的数据经过格式转换与 View 进行沟通。
MVP 设计模式通常会再加上 Controller 做为整体应用进程的后端进程工作。
实作
Java
在Java(AWT/Swing/SWT)应用程序里,MVP模式可以通过让用户接口类别实行视图接口(view interface)来运作。
相同的方法可以用在Java根基于网页的应用程序,因为现代Java根基于组件的网页框架允许使用和胖客户端(thick clients)相同的逐项布置法(component approach)客户端逻辑的开发。
在Google Web Toolkit里使用MVP只需要一些组件实行视图接口。相同的方法在Echo2网页框架里也能使用。
Google Web Toolkit - MVP
- Google Web Toolkit 结构:Best Practices For Architecting Your GWT App[1]
- Large scale application development and MVP [2]
- gwt-presenter[3]
参考资料
外部参考
- GWT: Model-View-Presenter Architecture Diagram, https://web.archive.org/web/20100121031446/http://www.nieleyde.org/SkywayBlog/post.htm?postid=37782056-c4e1-4dfb-9caa-40ab9552ca3b
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.