简体   繁体   English

Javaxfx:MVP(主管控制器)必须查看对演示者(控制器)的保留引用

[英]Javaxfx: MVP (Supervising Controller) must view keep reference to presenter (controller)

I want to implement MVP (Supervising Controller) with JavaFX. 我想用JavaFX实现MVP(监督控制器)。 I've studied several examples in internet and saw that view keep reference to presenter. 我已经研究了互联网上的几个示例,并看到该视图一直与演示者保持联系。 Is this right? 这是正确的吗?

I thought that view should not know about presenter at all. 我认为这个观点完全不应该关于主持人。 There is biderectional data binding between view and model VIEW<->MODEL although view doesn't keep reference to model. 尽管视图未始终引用模型,但视图和模型VIEW <-> MODEL之间存在投标数据绑定。 And presenter (controller) which knows about view (but works with view via interface) and model and handles all events. 演示者(控制器)知道视图(但通过接口与视图一起使用)并建模并处理所有事件。 Model knows neither view nor presenter. 模型既不了解视图,也不了解演示者。

I usually explain the difference as follows: 我通常解释如下差异:

  • If your view has a reference to a model and/or a controller/presenter, that indicates your view has at least some responsibility to set itself up or maintain itself. 如果您的视图引用了模型和/或控制器/演示者,则表明您的视图至少负有建立或维护自身的责任。 In this case your controller isn't fully responsible for the view, so you call it a Supervising Controller. 在这种情况下,您的控制器对视图不完全负责,因此您将其称为“监督控制器”。
  • If your view has no references to a model or controller/presenter whatsoever, it cannot do anything on its own and is completely passive, so you're using the Passive View pattern. 如果您的视图完全没有引用模型或控制器/演示者,则它不能自行执行任何操作并且完全是被动的,因此您使用的是“被动视图”模式。

If you're using FXML, you're most likely using Passive View, as FXML cannot specify any logic (other than maybe a name of a controller class and names of event handler methods) and your controller is responsible for setting up the view and maintaining it. 如果您使用的是FXML,则最有可能使用Passive View,因为FXML无法指定任何逻辑(可能不是控制器类的名称和事件处理程序方法的名称),并且您的控制器负责设置视图和维护它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM