MVC与javaFX [英] MVC with javaFX

查看:160
本文介绍了MVC与javaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javaFX挣扎于MVC概念。我正在使用fxml文件构建一个javaFX应用程序。

I'm struggling with the MVC concept using javaFX. I am building an javaFX application using fxml files.

每个fxml文件都分配了一个控制器,但我不认为这个控制器是MVC模式所述的控制器。我认为它像某种ViewController,它保存对fxml对象(按钮,窗格等)的引用。

Each fxml file has a controller assigned, but I don't think that this controller is one as the MVC pattern states. I think of it like some sort of ViewController, which holds references to fxml objects (buttons, panes etc.).

我的问题是:这到底有什么区别ViewController和真正的Controller。什么对象应该做什么事情?我在哪里设置,例如的ActionListeners?

My problem is: Where exactly is the difference between this "ViewController" and the real "Controller". What object should do what things? Where do I set e.g. actionListeners?

推荐答案

关于MVC的想法

MVC是一个非常松散定义的模式,它对MVC中的每个事物(特别是控制器)所代表的内容(通常有些模糊)的解释是开放的。关于Martin Fowler的GUI工具包,有一个很棒的关于MVC架构的讨论

MVC is a pretty loosely defined pattern which is open to (often somewhat vague) interpretations of what each of the things in MVC stand for (especially the controller). There is a great discussion of the MVC architecture with respect to GUI toolkits by Martin Fowler.

关于设计模式和FXML

基于JavaFX核心FXML的处理是为了更多的工具包而不是完整的开发框架。其他框架可以在JavaFX和FXML以及底层JavaFX / FXML实现和它们的控制器之上进行分层的想法不会在更高级别的框架上推动任何类型的议程或架构约束。

JavaFX core FXML based processing is built to be more of a toolkit rather than a complete development framework. The idea being that other frameworks could be layered on top of JavaFX and FXML and the underlying JavaFX/FXML implementations and the controllers for them would not push any kind of agenda or architectural constraints on the higher level frameworks.

因此,基于核心FXML的处理及其控制器与MVC架构之间存在故意松散的类比和映射。

As a result, there is a deliberately loose analogy and mapping of core FXML based processing and their controllers to an MVC architecture.

参见 JavaFX和MVP - 设计模式的smörgåsbord,供进一步讨论。

See JavaFX and MVP – a smörgåsbord of design patterns for further discussion.

考虑使用更高级别的框架

您可能会受益于采用自以为是的JavaFX框架,例如afterburner.fx ,它利用了控制器和FXML,但提供了更多严格的结构化框架。 Afterburner.fx遵循模型视图演示者(MVP)模型。尽管Afterburner.fx提供了比普通核心JavaFX + FXML更多的功能和结构,但它通过添加一些您需要学习使用它的额外类和API以最小的方式实现。

You might benefit from adopting an "opinionated" JavaFX framework such as afterburner.fx, which utilizes controllers and FXML but provides a bit more of a rigid structured framework. Afterburner.fx follows a Model View Presenter (MVP) model. Though Afterburner.fx provides more functionality and structure than plain core JavaFX+FXML, it does so in a minimal way by adding few extra classes and APIs that you need to learn to use it.

这篇关于MVC与javaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆