tags:

views:

1479

answers:

6

I'm looking for recommendations on books about MVC on the desktop. If they use Java, that is a bonus.

Some background: I'm writing a desktop application in Java. It's an audio application that has a number of views and a central model called a Library with playlists, effects lists and a folder structure to organize them. In this application I'd like to have menus, context-menus and drag and drop support for various user actions. I've been struggling with how to achieve this using MVC.

I started with all the logic/controllers in the main class but have started to separate them out into their own classes. Now I need to start using listeners and observers to handle messages between the views and the controller. This led to me creating a number of interfaces and looping through my listeners in several places to fire off various messages. But that loop code keeps getting repeated (not DRY), so I'm assuming that now I should create different types of Event classes, create those events in my views and use a single method within the view to fire it off to the various listeners.

Update: Arguabley it shouldn't matter much but I'm using SWT, not Swing.

+2  A: 
anjanb
A: 

Don't forget the Swing Tutorials; for instance the Swing Events tutorial.

And please bear in mind the SwingWorker, or handling events in a separate worker thread. I'm no expert on Swing by any means but I do know that a lot of the perceived slowness of Java Desktop applications is due to the work done in the event thread. If such work takes some time the entire GUI is unresponsive. Hard to fix afterward, not all that hard to do right if you keep it in mind.

As for books, I found the Core Java series by Cay Horstmann and Gary Cornell very nice to read. It is however about Java (including Swing) and not about MVC.

extraneon
+2  A: 

In C# rather then Java, but Jeremy Miller has a bunch of posts regarding desktop apps and MVP/MVC (and a whole bunch of other related stuff).

Yuval
A: 

I need to add to my above entry that the free BOOK -- THINKING IN JAVA talks about OOP, MVC and also about Swing. Not sure if it discusses the various implementations of MVC, though.

anjanb
+4  A: 

I've had the same problem: it really takes a lot of discipline to write a (non trivial) swing app, because all the listeners and events and asynchronous processing make up really fast for a big pile of unmaintainable code.

I found that classic MVC isn't enough, you have to look into more specific patterns like Presentation Model and such. The only book I found covering this patterns when applied to desktop applications is Desktop Java Live, by Scott Delap. While the majority of swing books deal with techniques to solve specific problems (how to make a gridless jtable, how to implement a round button, ...), Delap's book will help you architect a medium-sized swing application, best practices, etc.

alves
+1  A: 

Just to throw in my 2 cents, I recommend the book Head First Design Patterns. It has a very good explanation of the MVC pattern (in Java). It builds on other design patterns also discussed in the book such as Observer, Strategy and Composite that are used in MVC.

Best MVC tutorial I've read. Highly recommended.

urini