[英]Should I use a framework?
I know this question is vague, but I'll try to make myself clear. 我知道这个问题很模糊,但我会尽力让自己清楚。
I am starting a Java project involving a Swing GUI. 我正在启动一个涉及Swing GUI的Java项目。 I want to follow the MVC pattern, and could use some help from a framework to organize the project's architecture.
我想遵循MVC模式,并可以使用框架中的一些帮助来组织项目的体系结构。 I was thinking of using Griffon , though I suppose others might do the trick.
我正在考虑使用Griffon ,尽管我认为其他人可能会这样做。
So, is it a good idea to use a framework in terms of: 那么,在以下方面使用框架是一个好主意:
Programming efficiency: Of course, it will be improved... most of the time . 编程效率:当然,它会在大多数时候得到改善。 More precisely, what if the project is a small one?
更准确地说,如果项目是一个小项目怎么办? Or a large one?
还是一个大的? What if I'm already very familiar with Java and Swing?
如果我已经非常熟悉Java和Swing怎么办? What if I'm not?
如果我不是怎么办? What if the project has to be maintained by someone who knows nothing about the framework I used?
如果项目必须由对我使用的框架一无所知的人维护,该怎么办?
Learning value: Will I merely "learn how to use the framework", instead of learning more about Java and Swing in a different environment? 学习价值:我是否只是“学习如何使用框架”,而不是在不同的环境中学习更多关于Java和Swing的知识?
Professional value: Would companies prefer a developer who knows "more" frameworks (even if they might not be the ones they intend to use) to a developer who knows the "traditional" approach better? 专业价值:对于更了解“传统”方法的开发人员,公司是否更喜欢知道“更多”框架的开发人员(即使他们可能不是他们打算使用的框架)?
I found little information elsewhere, which is surprising, considering how big this question is. 考虑到这个问题有多大,我在其他地方发现的信息很少,这是令人惊讶的。 It might seem trivial, but I'm actually wondering about it.
这看起来似乎微不足道,但我实在想知道它。
Of course I'm biased when it comes to Griffon however I'll try to be as objective as possible: 当然,我对Griffon有偏见,但我会尽量做到客观:
But in the end there's only one opinion that matters: yours. 但最终只有一个重要的意见:你的意见。 I'd recommend you to spend a few hours with Griffon, if you don't see the value added by it by then ... I'm afraid we'll have to work harder to make it better.
我建议你和Griffon一起花几个小时,如果你还没有看到它增加的价值......我担心我们必须更加努力才能让它变得更好。
Cheers 干杯
As we know, Griffon is based on Groovy and Groovy has a beautiful Java style , probably you will avoid lots of code line, but always we need to consider some aspects like knowledge and schedule. 我们知道,Griffon基于Groovy而Groovy有一个漂亮的Java风格 ,可能你会避免很多代码行,但我们总是需要考虑知识和时间表等方面。
So, consider to use what you know, and study new things to another projects. 因此,请考虑使用您所知道的内容,并将新内容研究到另一个项目中。
Avoid diving in the dark without your flashlight.
避免在没有手电筒的情况下在黑暗中潜水。
I was evaluating Griffon as a framework. 我正在评估Griffon作为一个框架。 I got the impression that this project is slowly dieing.
我觉得这个项目正在慢慢消亡。 IMHO Groovy is not a mainstream anymore (I wonder if it ever was a mainstream?).
恕我直言Groovy不再是主流(我不知道它是否曾经是主流?)。 Now everybody fancies Scala.
现在每个人都喜欢Scala。
Now back to your question: 现在回到你的问题:
Implementing the MVC pattern for an environment should be easy if you understand it. 如果您了解环境,则应该很容易实现环境的MVC模式。 First a note on it: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
首先给它一个注释: http : //en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
Now coming to your environment which is Swing based, you can implement your code by dividing it Model-View-Controller. 现在进入基于Swing的环境,您可以通过将其划分为Model-View-Controller来实现您的代码。 Views are your Swing classes where are you are actually creating the user interface.
视图是您的Swing类,您实际上是在哪里创建用户界面。 In such classes, you should simply capture the user actions through different listeners but should not implement any business logic.Controller should be doing the business logic and may use Model whenever desired.
在这些类中,您应该通过不同的侦听器捕获用户操作,但不应实现任何业务逻辑。控制器应该执行业务逻辑,并且可以在需要时使用模型。
For example, you are creating a Swing GUI for login. 例如,您正在创建用于登录的Swing GUI。 Create a LoginView class where you will create the frame, textfields, buttons etc. And also attach the listeners to different controls as desired.
创建一个LoginView类,您将在其中创建框架,文本字段,按钮等。还可以根据需要将侦听器附加到不同的控件。 Now whenever a user submits the login, you should call controller to do the credentials validation.
现在,只要用户提交登录信息,就应该调用控制器来进行凭据验证。 Credentials may be stored in a DB, which should be loaded and stored in Model(DAOs).
凭证可以存储在DB中,应该加载并存储在模型(DAO)中。 Controller should get the user input from View, correct credentials from Model, and the compare logic should be implemented in Controller.
控制器应从View获取用户输入,从Model中更正凭证,并且应在Controller中实现比较逻辑。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.