控制器在 MVC 中的角色

发布于 2024-12-24 01:41:13 字数 283 浏览 2 评论 0原文

我正在尝试用 java 构建一个简单的 GUI 应用程序,它将向我显示美元与欧元、英镑等的汇率。

该模型连接到 URL 并废弃 Web 数据以构建包含汇率的哈希图。

该视图有一个 JcomboBox,用户可以在其中选择要在 JTextArea 中显示的汇率。

程序启动后,模型不会更新。当程序启动时,Main 类会构建所有必需的对象。

鉴于这些(并且模型不会更新)是否需要控制器类?控制器似乎只是用于更新模型,所以我对如何使用控制器构建这个 MVC 有点困惑。希望这一点是清楚的。提前致谢

I am trying to build a simple GUI app in java that will show me the exchange rates for USD with EUR, GBP etc.

The model connects to a URL and scraps the web data to build hashmaps containing exchange rates.

The view has a JcomboBox where the user selects the exchange rate to be displayed in JTextArea.

There is no update to the Model once the program starts. When, the program starts the Main class builds all the necessary objects.

Given these (and there will be no update to the model) is a controller class necessary? It seems that a controller is only used to update the model so I am a bit confused about how to construct this MVC with a controller. Hope this was clear. thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-12-31 01:41:13

我想正确的解决方案需要控制器从 URL 获取数据,构建模型并将其推送(MVP)或发布(MVC)到视图/视图。
但说实话,如果没有必要,不要强制使用 MVC。毕竟,它的目的是帮助管理复杂的场景,如果您怀疑它是否有必要,那么它可能没有必要。

I guess the proper solution would require Controller to fetch data from URL, construct Model and push (MVP) or publish (MVC) it to/for View.
But to be honest, do not force MVC if it's not necessary. After all it is meant to help with managing complex scenarios, if you are in doubt if it even necessary then it probably is not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文