学到了一个新名词:MVP模式

MVP可以跟MVC对照起来看。和MVC一样,MVP的M就是 Model, V就是View,而P,则代表Presenter,它与Controller有点相似。

不同的是,在MVC中V会直接展现M,而在MVP中V会把所有的任务都委托给P。V和P会互相持有reference,因此可以互相调用。这也暗示着V肯定是一个富的客户端。

维基百科的介绍是:

In this formulation, when a user triggers an event method of the view, it does nothing but invoke a method of the presenter which has no parameters and no return value. The presenter then retrieves data from the view through methods defined by the view interface. Finally, the presenter then operates on the model and updates the view with the results of the operation.

它还举了三个MVP的例子:

   In a Java
(AWT/Swing/SWT) application, the MVP pattern can be used by letting the UI class implement a view interface.

The same approach can be used for Java thin (web based) applications since modern Java Component Based Web Frameworks allow development of client side logic using the same component approach as thick clients. To implement MVP in
Google Web Toolkit one just needs to let any component implement the view interface. The same approach is possible using the
Echo2 web framework.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.