用于用户操作验证的 Java Swing GUI 设计技术 (MVC-FSM)

发布于 2024-10-10 12:16:00 字数 849 浏览 1 评论 0原文

我已经使用 Swing 实现了 GUI,并且总是尽可能地遵循 MVC 模式。
但我想知道 MVC 是否不是这个难题的唯一部分。
GUI 的设计中也使用了 FSM 吗?
我从未在 GUI 中使用过 FSM,我的方法是:在操作时,调用控制器的相应方法,最终更新模型,完成更新视图。
通常,根据用户操作触发的请求,我使用一些简单的检查来确保用户应该能够执行此类操作:是否启用了特定组件?或者这种标签是可见的吗?等等
到目前为止,这似乎有效,但我不得不承认我很“幸运”,不需要构建太复杂或复杂的 GUI。
我之前已经构建过 FSM(在不同类型的应用程序中 - 主要是在 C++ 中),并且我开始怀疑 GUI 中的 FSM 是否实际上用作一种模式,而我的方法是对 ActionListeners 代码、用户看到的内容以及组件进行检查启用或禁用等,以确定用户是否应该看到一些错误消息,而不是能够执行特定操作,例如按钮承诺对于成熟的 GUI 应用程序来说实际上是一个坏主意。
那么,当开始设计 GUI 时,除了如何实现 MVC 之外,您还会在设计中安装/关联 FSM 吗?
更新:
在评论中回顾了 Dhruv Gairola 的文章后,我仍然对此感到困惑。
该文章提到构建一个 FSM,尽管它实际上绑定到计算器实现,这意味着即使计算器实现为在没有 GUI 的情况下通过命令行获取用户输入,仍然需要 FSM。
我仍然不确定用于验证用户在每个时间点的操作的 FSM 是否是流行或有效的设计。
看起来这可能需要花费太多精力,并且需要完全提前设计 GUI,并且所有可能的用户操作都已根据特定状态映射到特定结果。
鉴于没有任何评论,只有一个回复,我倾向于认为可能实际上没有使用 FSM(验证用户对控件的操作)。

非常欢迎对此提出任何意见。
谢谢。

I have implemented GUIs using Swing and always tried to follow the MVC pattern as much as I could.
I was wondering though, if MVC is not the only part of the puzzle.
Are FSMs used in GUI's design as well?
I have never used an FSM in a GUI and my approach was: on action, the corresponding method of the controller was called, to endup updating the model, finishing with updating the view.
Usually upon a request triggered by a user's action I used some simple checks to make sure that the user should be able to do the action of the kind:is a specific component enabled? or is the label visible of this kind? etc.
This seems to work so far, but I have to admit that I was "lucky" and did not have to build too complicated-sophisticated or elaborate GUIs.
I have build FSMs before (in different kind off applications -mainly in C++) and I started to wonder if FSMs in GUIs is actually used as a pattern and my approach i.e. to make checks on ActionListeners code, on what the user sees plus what components are enabled or disabled etc. to determine if the user should see some error message instead of being able to do the specific action that e.g. the button promises is actually a bad idea for full-fledged GUI apps.
So when starting to design a GUI besides how to implement the MVC do you fit/associate an FSM in your design?
UPDATE:
After reviewing Dhruv Gairola article in his comment, I am still puzzled on this.
The article mentions building an FSM which is though actually bind to the calculator implementation, meaning that even if the calculator was implemented getting user input without a GUI but via the command line, the FSM would still be needed.
I am still not sure if FSMs to validate user's action on each point in time, is a popular or valid design.
It seems that it could be too much effort and requires that the GUI has been designed completely in advance and all the possible user's action have been mapped to specific results depending on specific states.
Given the fact that there has no been any comments just a one reply, I am tending to think that may be FSM's (to validate a user's actions on controls) are actually not used.

Any input on this is highly welcome.
Thank you.

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

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

发布评论

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

评论(1

很酷不放纵 2024-10-17 12:16:01

让我们这样说——设计模式主要是对不同设计原则的阐述,例如封装变化的内容、对接口进行编程,而不是实现等。因此,您不必使用模式或任何东西,基本上要确保您的编程方式符合良好的设计原则。如果将 FSM 用于特定设计具有设计意义,我建议您采用它。通常鼓励使用模式,以便其他程序员能够理解您的逻辑,并根据他们对模式的了解轻松地对其进行扩展。没有严格的规则说你必须使用 MVC,你必须使用等等等等。结论:只要你应用的模式符合良好的设计原则,(或者即使你没有使用特定的模式) ),确保它的设计足够好,足以让其他人轻松扩展和理解它。这就是我的两分钱的价值..

lets put it this way- design patterns are mainly elaborations of the different design principles e.g. encapsulate what varies, program to an interface, not an implementation, etc. so its not that you HAVE to use a pattern or anything, basically make sure that the way you program conforms to good design principles. if using FSM for a particular design makes design sense, id advice you to go for it. usually patterns are encouraged so that other programmers are able to understand your logic and expand on it easily based on what they know about the pattern. theres no rigid rule saying that you HAVE to use MVC, you HAVE to use blah blah blah.. conclusion: as long as the pattern you're applying conforms to good design principles, (or even if you're not using a specific pattern), make sure its designed well and well enough for others to expand and understand it easily. thats my two cents worth..

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