简体   繁体   English

我应该使用框架吗?

[英]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有偏见,但我会尽量做到客观:

  • Griffon is an MVC framework/platform for the JVM. Griffon是JVM的MVC框架/平台。 It's true that the programming language of choice is Groovy, however many others can be used too, see this example from the Guide http://griffon.codehaus.org/guide/latest/guide/tips.html#nonGroovyArtifacts where it shows how a pure Java application can be written. 确实,选择的编程语言是Groovy,但是也可以使用其他许多语言,请参阅指南中的这个示例http://griffon.codehaus.org/guide/latest/guide/tips.html#nonGroovyArtifacts ,其中显示了如何可以编写纯Java应用程序。 Other options are possible if you install a specific plugin http://artifacts.griffon-framework.org/tags/plugin/polyglot 如果您安装特定插件,则可以使用其他选项http://artifacts.griffon-framework.org/tags/plugin/polyglot
  • Griffon's philosophy is one of keeping your choices open. 格里芬的理念是让你的选择保持开放。 It's true that sometimes the framework will steer you to follow particular path however it has provides plenty of leg room, that is, you make it dance to your own tune. 确实,有时框架会引导你走特定路径,但是它提供了足够的腿部空间,也就是说,你可以按照自己的曲调跳舞。 For example, writing Views is usually done following the Groovy SwingBuilder DSL (a subtle abstraction layer on to of Swing), but you can drop down to the Java layer and write in plain Java/Swing if you want; 例如,编写Views通常是在Groovy SwingBuilder DSL(Swing的一个微妙的抽象层)之后完成的,但是如果你愿意,你可以下载到Java层并用普通的Java / Swing编写; or pick NetBeans Matisse, Abeille Froms Designer, or any other Visual tool that supports Swing. 或选择NetBeans Matisse,Abeille Froms Designer或任何其他支持Swing的Visual工具。
  • Plugins are key to Griffon's success. 插件是Griffon成功的关键。 As you can see at http://artifacts.griffon-framework.org/category/all/plugins there are currently 211 plugins, and more are coming. 正如您在http://artifacts.griffon-framework.org/category/all/plugins上看到的那样,目前有211个插件,还有更多插件即将推出。

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风格 ,可能你会避免很多代码行,但我们总是需要考虑知识和时间表等方面。

  • Knowledge : Your productivity is related with what you know and how to use what you know, if you feel confortble in Java, use the Java, because, seems that your goal is to use MVC and as Juned said, we can do this with Swing, too. 知识 :你的工作效率与你所知道的以及如何使用你所知道的相关,如果你觉得Java很难,使用Java,因为,你的目标似乎是使用MVC,正如Juned所说,我们可以用Swing做到这一点也是。
  • Schedule : If you have time to study and really want to learn a new framework now, this is the time, but you must to follow your schedule, don't forget that you need to finish this project in the time. 时间表 :如果你有时间学习并且现在真的想学习一个新的框架,现在是时候了,但你必须按照你的日程安排,不要忘记你需要在当时完成这个项目。

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: 现在回到你的问题:

  • Most frameworks expect that you follow the standard development path. 大多数框架都希望您遵循标准的开发路径。 Any changes / customizations will most probably introduce difficult to maintain solutions (they will call it architecture afterwards). 任何更改/自定义都很可能会引入难以维护的解决方案(之后他们称之为架构)。 Choose a framework that allows you to do 95% of the things you plan to do. 选择一个框架,允许您完成95%的计划。 And yeah, choose a mainstream framework. 是的,选择一个主流框架。
  • Griffon is based on Groovy, so you have to master Groovy first. Griffon基于Groovy,所以你必须先掌握Groovy。 Ok, Groovy is a JVM language and if you're OK with Java it will greatly help, but still all those DSLs will require some time to settle in your head. 好的,Groovy是一种JVM语言,如果你对Java很好,那将会有很大的帮助,但是所有这些DSL都需要一些时间才能解决问题。
  • If you know any mainstream framework - this is a valuable asset. 如果您了解任何主流框架 - 这是一项宝贵的资产。 The sad fact is that frameworks tend to fade / die and you have to constantly look for new buzz things. 可悲的事实是,框架往往会褪色/死亡,你必须不断寻找新的嗡嗡声。 You never stop learning (although key principles cannot be changed and remain constant from framework to framework) 你永远不会停止学习(虽然关键原则不能改变,并且从框架到框架保持不变)

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.

相关问题 为什么我应该在Java应用程序上使用Spring核心框架 - Why should I use Spring core framework over java application 我应该使用哪种设计模式? 使用Spring框架 - What design pattern should I use ? using spring framework 我是否应该使用OVal(对象验证框架),即使它不需要AspectJ? - Should I use OVal (Object Validation Framework) even if it requires AspectJ or not? 我应该使用报告框架吗? - Should I be using a reporting framework? 我应该使用改装休息客户端,因为我已经在我的webapp中使用了Spring框架 - Should I use retrofit rest client given I am already using Spring framework in my webapp 我应该使用 Bean Scripting Framework 还是 JSR 223 javax.script ? - Should I use Bean Scripting Framework or JSR 223 javax.script ? Hamcrest是否包含测试运行器,还是我应该使用其他框架的运行器? - Does Hamcrest contain test runner or should I use a runner from another framework? 我应该使用哪种同步原语在Java中实现事件驱动程序框架? - What synchronization primitive should I use to implement a event driver framework in Java? 我应该使用Web框架来实现一堆可能不会改变的外部链接吗? - should i use the web framework for implementing a bunch of external links that likely won't change? 为什么我要避免代码中的对象实例化并使用Spring框架? - Why should I want to avoid object instantiation in code and use the Spring framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM