English 中文(简体)
示范意见的提交者是否产生看法?
原标题:Does Presenter in Model-View-Presenter create views?
  • 时间:2011-06-06 07:36:24
  •  标签:
  • theory
  • mvp

MVP如何产生看法? 提交者是否总是创建这些职位(除了在分观点方面的观点之外)? 或者,它是一个单独的第三方组成部分或应用,还是产生这些成分的东西?

我还要指出,我很可能在Dojo Toolkit/ExtJS(Java编)上这样做。

因此,我有这些法典:

var v = new MyApp.view.User();
var p = new MyApp.presenter.User();

这两条路线究竟在何处? 陈述人是否即时表示意见,还是反面意见? 什么是初审?

最佳回答

它取决于......

The main goal of MVP is to separate complex decision logic from UI code in such a way that both become easier to understand and to maintain. Often another goal is to make the decision logic in the presenter testable.

The MVP pattern was described by Fowler in 2004 and he retired it in 2006 by splitting the pattern into Supervising Conroller (SC) and Passive View (PV). In SC, the View is bound to the Model but not in PV; in PV, the View is only changed by the Presenter directly.

在SC和PV中,提交者必须更新意见,对用户对意见所作的改动作出反应,例如进入案文或将一个纽扣。 当您请见面人时,就会出现你描述的问题,因为观点需要提及发言者,反之亦然。 如果你这样做,那么你就能够作出决定,由谁来决定。 备选办法如下:

  1. The View creates an instance of the Presenter. When the View is loaded, it passes itself to the Presenter in an initialize function on the Presenter.
  2. The other way around: Presenter creates View and passes itself to the View in an initialize function on the View.
  3. You introduce a third object that creates both View and Presenter, wires them together and initializes them both.

All options allow you to reach "MVP goals" of separation of concerns and increased testability of decision logic. I don t think any of these methods is theoretically right or wrong –you just have to pick the one that is most appropriate to the technology you use. And it s best to be consistent in your choice throughout the application.

问题回答

These are your options:

var cvp = new ContactViewPresenter(new ContactView());

ContactViewPresenter constructor sets this.view = viewParam, and sets this.view.presenter = this. It keeps the code in the Presenter, it can swap out views if necessary, and it could pass in a mock of the view for testing.

var cv = new ContactView(new ContactViewPresenter());

ContactView constructor sets this.presenter = cvpParam, and this.presenter.view = this. Some logic in View, but not a lot. Can swap out presenter if necessary.

ContactView cv = new ContactView();
ContactViewPresenter cvp = new ContactViewPresenter();
cv.presenter = cvp;
cvp.view = cv;
cv.init();
cvp.init();

这是更多的法典。

ContactViewPresenter cvp = new ContactViewPresenter();

Constructor创设了this.view = 新的联系意见(this.view.presenter = 这一

ContactView cv = new ContactView();

Constructor set this.presenter = new CrossViewPresenter( and this.presenter.view = this

最后两条似乎太过了。

一种看法是,该守则在提交者中停留,似乎便于测试。

两点是,你不必过多地照顾到发言者,并对你们感到担忧。 更多意见。

I< t>,theer view, that should be Immediateiate, that should do be made by an entities (>, in the data-Orientness, I mean a general entities) than the MVP. 例如,控制(IoC)框架(如果你听说过IoC, «a href>http://martinfowler/com/in>. > > > < > > > >。 Martin Fowler s articles/a, 或者, 或者 某些申请是:

如果你使用网上表格,那么网上网站“Load”或“Init”就应当成为你创建网站的地方,然后通过一个接口,提及网上论坛所执行的观点。

因此:

Presenter _presenter;

OnLoad(object sender, EventArgs e) 
{
  _presenter = new Presenter(this);
  _presenter.Initialise();
}

因此,目前建筑商的定义是:

public class Presenter
{
  public Presenter(IView viewReference)
  {
    _viewReference = viewReference;
  }
}

我的术语可能有些错误,但我认为你需要确定你们互动的构成基础;开始互动的是什么?

In the Webforms example I gave, the Webform is created by the Http pipeline, the OnInit or OnLoad event is the first point in the pipeline ( depending on what context you need ) that you can hook in to the process. Thus, you create a Presenter and give it your concrete instance of a Webform as a View Interface.

I don t know the Javascript frameworks you are discussing but I presume there is an initialisation / invocation step - in ASP.NET MVC this is when an ActionInvoker gets involved, it s the Main in a Console App.





相关问题
Is transactions over machine boundary (via tcp-ip) possible?

Theoretically, can one define a protocol where one machine does some remote calls on another machine (or more than one), and where in any part of the process, if any of the machines (or operations) ...

How to write an enumeration of all computable functions?

Motivation: I d like to be able to use toy functional programming in languages without first-order functions, by using natural numbers instead of functions. A universal function is a function f : N ->...

Best-case Running-time to solve an NP-Complete problem?

What is the fastest algorithm that exists up with to solve a particular NP-Complete problem? For example, a naive implementation of travelling salesman is O(n!), but with dynamic programming it can be ...