tags:

views:

624

answers:

3

I will start a Java project to develop a desktop application. What to use as presentation layer pattern (MVC, MVP,MVVM or....)?

...if it is possible, with some working small example... :-)

Thanks.

A: 

I'm not a fan of MVC. The whole "separation of concerns" argument is so frequently parroted that I really doubt that most of those who repeat it really understand what they're saying.

In a C# web app, for instance, pages are composed of an ASPX file (which contains markup and control declarations) and a .cs file which contains code. The .cs file is dedicated to supplying data to the aspx in whatever form it expects. MVC forces you to combine these two things into one module, placing code within the markup. That falls under "combination of concerns" in my book, overcomplicating development and maintenance, and producing a maintenance nightmare by making the markup damn near unreadable.

The MVC bandwagon has a lot of passengers. That doesn't mean its the right way to go. Good application design with a tiered, clearly delineated approach is far more important than choice of frameworks, if any.

David Lively
A: 

Hi Andrea,

I would also recommend you to use Google to find more information since your question is really vague. Anyway, since you want to do your desktop application in Java, and you'll probably use Swing, I just want to point that Swing is designed with a MVC pattern in mind. Anyway you can easily modify it to a MVP using some extra interfaces.

If you're unsure about the pattern, I would recommend to use the MVC. You'll find much more examples.

My 2 cents.

Carlos Tasada
+4  A: 

Actually, the ultimate post you're looking for is this answer from Karsten Lentzsch (of JGoodies fame) in the Swing Frameworks and Best Practices thread. If you don't know Karsten and JGoodies, then believe me, this guy really knows what he's talking about. I warmly recommend to read carefully his answer and the material he posted as reference. More specifically, be sure to check his Desktop Patterns and Data Binding presentation. Surprisingly, I prefer the old version to the new one.

Let me quote his slide about MVC vs MVP:

  • Yes, Swing uses an extended form of MVC internally
  • But MVC is for components, MVP is for applications

And then from the Summary:

But I can't do a better job than Karsten at explaining this, I can at best paraphrase him. So just read him!

Also maybe have a look at Desktop Java demos for learning (more precisely Scott Violet's answer).

Pascal Thivent