8

I know this question is vague, but I'll try to make myself clear.

I am starting a Java project involving a Swing GUI. I want to follow the MVC pattern, and could use some help from a framework to organize the project's architecture. I was thinking of using Griffon, though I suppose others might do the trick.

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? 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?

  • 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.

Aeronth
  • 804
  • 1
  • 6
  • 16

4 Answers4

6

Of course I'm biased when it comes to Griffon however I'll try to be as objective as possible:

  • Griffon is an MVC framework/platform for the JVM. 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. Other options are possible if you install a specific plugin 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; or pick NetBeans Matisse, Abeille Froms Designer, or any other Visual tool that supports Swing.
  • Plugins are key to Griffon's success. As you can see at http://artifacts.griffon-framework.org/category/all/plugins there are currently 211 plugins, and more are coming.

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.

Cheers

Andres Almiray
  • 3,236
  • 18
  • 28
  • 2
    Thank you ! However, my question was actually aimed at frameworks in general — I think Griffon would be a good choice if I decide to use one. I am a beginner at writing GUIs, and I find creating a Swing app from scratch needlessly painful, considering I am only following standards. Still I want to write plain Java since I would like to learn it. So I figured a framework would at least provide the starting architecture, and possibly more. That's why. – Aeronth May 03 '13 at 14:30
5

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.

  • 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.
  • 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.

3

I was evaluating Griffon as a framework. 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?). Now everybody fancies 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. And yeah, choose a mainstream framework.
  • Griffon is based on Groovy, so you have to master Groovy first. 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.
  • 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)
WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
  • Thank you for this practical answer. – Aeronth May 03 '13 at 12:45
  • 2
    I'm afraid Scala is more hype than anything else these days. Anyway, Griffon supports Scala too (soon ScalaFX), so it's as mainstream as Scala can be (by your own reckoning). – Andres Almiray May 03 '13 at 13:23
  • @aalmiray from the plugin docs: it (scala) will be compiled first before any sources available on griffon-app or src/main which means you can't reference any of those sources from your Scala code. And yeah, I didn't want to hurt anyone feelings ;) I've got a project on Grails myself. – WeMakeSoftware May 04 '13 at 06:45
  • @aalmiray One more thing. The Scala plugin for Griffon was last updated in january 2011. – WeMakeSoftware May 04 '13 at 06:51
  • @Funtik the latest release of the Scala plugin was posted 04/10/2013 as a matter of fact http://artifacts.griffon-framework.org/plugin/scala/releases you might have seen a previous page http://griffon.codehaus.org/Scala+Plugin that one, is no longer active – Andres Almiray May 06 '13 at 03:33
  • @aalmiray what about my first comment? Can the compiled sources be shared? – WeMakeSoftware May 06 '13 at 08:35
  • @Funtik code may be shared if placed under `src/scala-commons` and `src/commons`, however consider that there's no joint compiler capable of compiling Scala and Groovy code in a single step. You may define interfaces/traits in those directories, then have the code in `griffon-app` or even `src/main` refer to those definitions; the code under `src/scala` should be able to see all those classes too. – Andres Almiray May 06 '13 at 14:49
2

Implementing the MVC pattern for an environment should be easy if you understand it. First a note on it: 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. Views are your Swing classes where are you are actually creating the user interface. 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. Create a LoginView class where you will create the frame, textfields, buttons etc. And also attach the listeners to different controls as desired. 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). Controller should get the user input from View, correct credentials from Model, and the compare logic should be implemented in Controller.

Hope it helps!

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136