Java rich client design patterns: where to find?

D

diegomrosa

Hi all,

another possible title for this message would be:

Where can I find effective references on design patterns and best
practices to build complete and elegant Swing applications?

I have been developing Swing applications for about 3 years and never
got satisfied with the results. In the begining I was not using any
design pattern, just putting all my code there in the same class, so
you can imagine the mess. After some months I started looking for some
references on "building elegant Swing applications" and what I found
was very frustrating: there are very few _effective_ references on
that.

I think _effective_ is a very important word here. In fact, there are
thousands of sites and books describing Java technologies and another
thousand others explaining how to build a complete Web application
using J2EE technologies. The problem is finding references on building
a complete, real-life, java rich client application. This topic is so
controverse that one will find many terminologies to define the same
type of application: java rich client application, java desktop
application, java GUI application, Swing application. The situation
gets worse by the fact that people used MVC to build Swing. Then you
try googling "swing MVC" and thousands of sites explaining how Swing
was developed show up. The problem is I DO NOT WANT TO KNOW HOW SWING
WAS DEVELOPED, I WANT TO KNOW HOW TO DEVELOP GOOD APPLICATIONS USING
SWING! I have even tried to adapt some J2EE patterns to Swing
applications, but the results were definetly not good.

In fact, there are some sparse references describing how to build
complete Swing applications using patterns like Presentation Model and
Model-View-Presenter (MVP):
- Desktop Java Live: http://www.sourcebeat.com/TitleAction.do?id=10
- JGoodies: www.jgoodies.com
- Martin Fowler home-page: www.martinfowler.com
- Martin Fowler work-in-progress (Patterns of Enterprise Application
Architecture): www.martinfowler.com/eaaDev
- Spring Rich Client Project: www.springframework.org/spring-rcp
- Eclipse Rich Client Platform:
wiki.eclipse.org/index.php/Rich_Client_Platform
- The Humble Dialog Box:
www.objectmentor.com/resources/articles/TheHumbleDialogBox.pdf

The problem with this references is that the information is either not
uniform or not consistent. Each one explains MVP one way, with very
poor examples. It would be very good to see a complete source code
example of a Swing application using MVP and accessing a persistence
layer. Does anybody know where can I find that? Any book talking about
this topic would be very good too.

"It is our belief the only problem with Swing is that there are a
limited number of higher-level abstractions available that assist in
making the toolkit simpler and easier to use, and a limited number of
design best practices. The goal of spring-richclient is to provide
that." Spring Rich Client Project

Thanks in advance,
Diego M. da Rosa
diegomrosa at gmail dot com
 
O

Oliver Wong

[snip]
I think _effective_ is a very important word here. In fact, there are
thousands of sites and books describing Java technologies and another
thousand others explaining how to build a complete Web application
using J2EE technologies. The problem is finding references on building
a complete, real-life, java rich client application. This topic is so
controverse that one will find many terminologies to define the same
type of application: java rich client application, java desktop
application, java GUI application, Swing application. The situation
gets worse by the fact that people used MVC to build Swing. Then you
try googling "swing MVC" and thousands of sites explaining how Swing
was developed show up. The problem is I DO NOT WANT TO KNOW HOW SWING
WAS DEVELOPED, I WANT TO KNOW HOW TO DEVELOP GOOD APPLICATIONS USING
SWING! I have even tried to adapt some J2EE patterns to Swing
applications, but the results were definetly not good.
[snip]

The problem with this references is that the information is either not
uniform or not consistent. Each one explains MVP one way, with very
poor examples. It would be very good to see a complete source code
example of a Swing application using MVP and accessing a persistence
layer. Does anybody know where can I find that? Any book talking about
this topic would be very good too.

Maybe go straight to the source? ISBN: 0201633612.
http://www.amazon.com/gp/product/02...f=pd_bbs_1/102-4704180-0024120?_encoding=UTF8

This book only covers MVC though, not MVP. But after reading this book,
you should be able to "get" what design patterns are all about, it won't be
hard to learn new patterns (including MVP).

- Oliver
 
D

diegomrosa

Thanks a lot for your answer Oliver, but I have already read this book
(GoF) a couple of times. Believe me, I know what design patterns are
all about. Now, how can I learn about the MVP design pattern if I can
not find a single book describing it?

People, I am NOT searching references on:
- General purpose design patterns;
- J2EE design patterns;
- Swing and MVC.

All I want is a Java rich client design patterns and best practices
guide.

Diego
 
O

Oliver Wong

diegomrosa said:
Thanks a lot for your answer Oliver, but I have already read this book
(GoF) a couple of times. Believe me, I know what design patterns are
all about. Now, how can I learn about the MVP design pattern if I can
not find a single book describing it?

People, I am NOT searching references on:
- General purpose design patterns;
- J2EE design patterns;
- Swing and MVC.

All I want is a Java rich client design patterns and best practices
guide.

Well, I don't know of a book that is specifically about writing Java
Rich Client applications using design patterns. You still gotta do some
thinking yourself; if it were as easy as following a recipe in a book, you
wouldn't need programmers, you'd just answer a few questions in a wizard,
click "Ok", and out comes the application.

When I google for "Model View Presenter", the first hit I get is
http://www.martinfowler.com/eaaDev/ModelViewPresenter.html which explains it
pretty well, IMHO.

- Oliver
 
D

diegomrosa

Well, I don't know of a book that is specifically about writing Java
Rich Client applications using design patterns. You still gotta do some
thinking yourself; if it were as easy as following a recipe in a book, you
wouldn't need programmers, you'd just answer a few questions in a wizard,
click "Ok", and out comes the application.

You can be sure that is not what I want! Take a look at the Spring Rich
Client Project home-page and you will see that I am not the only person
in the world concerned about that (see quotation in the end of the
original message).
When I google for "Model View Presenter", the first hit I get is
http://www.martinfowler.com/eaaDev/ModelViewPresenter.html which explains it
pretty well, IMHO.

Well, you could have saved some time if you had copied this link from
my original message. IMHO it is a very good text, but it is far from
explaining it PRETTY well. The text is kind of superficial and the
example used by Martin is extremelly simple. Have you ever tried
writing a more complex application using this pattern? Well, I did and
I think there are some issues uncovered. Martin says something about
releasing this as a book and I hope it happens soon!

Diego
 
O

Oliver Wong

diegomrosa said:
You can be sure that is not what I want! Take a look at the Spring Rich
Client Project home-page and you will see that I am not the only person
in the world concerned about that (see quotation in the end of the
original message).

Projects that start to drift away from J2SE and towards J2EE make my
eyes glaze over, because they tend to get vague about what exactly they're
useful for. From http://www.springframework.org/spring-rcp:

<quote>
The goal of the Spring Rich Client Project (Spring Rich) is to provide a
viable option for developers that need a platform and a 'best-practices'
guide for constructing Swing applications quickly.
</quote>

To which I reply:

<reply>
Great. How does it accomplish that goal? By providing a JAR file I can
download? By publishing a book with a list of best-practices? By sacrificing
a goat on an altar to the good-code Gods?
</reply>

AFAICS, there's no further information on the project, other than they
simply "want" for it to be easier for developers, and that they don't plan
on reinventing the wheel. They don't answer questions like "How is your way
better than what I'm doing right now?" or even the more basic "Just what IS
your way?" But I digress...
Well, you could have saved some time if you had copied this link from
my original message. IMHO it is a very good text, but it is far from
explaining it PRETTY well. The text is kind of superficial and the
example used by Martin is extremelly simple. Have you ever tried
writing a more complex application using this pattern? Well, I did and
I think there are some issues uncovered. Martin says something about
releasing this as a book and I hope it happens soon!

To be honest, I what Fowler calls "MVP", I call "MVC", and what Fowler
calls "MVC", I call "a bad idea". From Fowler's page:

<quote>
Classic MVC doesn't work well with modern rich client tools because they
design things so that the view handles all the user events such as mouse and
keyboard clicks.
</quote>

The way I learned MVC, the controller actually handles the user events.

<quote>
In Model View Presenter the view continues to handle these, but then
immediately delegates these to the presenter. The presenter then decides
what to do with the event, communicating with the domain and the data in the
view's controls.
</quote>

When I write MVC, I'm actually writing what Fowler calls MVP. Since my
View is made up of the actual Swing widgets, yes, the View is "handling" the
event, but it immediately delegates to my "Control" object, so conceptually,
I'm thinking that my controller is the one... well... in control.

Finally, Fowler writes:

<quote>
Another style of Model View Presenter allows the view to update itself from
the model directly. In this case events are delegated from the view to the
presenter, and the presenter updates the model as before. However instead of
having the presenter update the view, the view draws its information
directly from the model. This clearly simplifies the presenter and removes
the need for the presenter to be dependent upon the view, or need an
interface for manipulating the view. However the view now needs to have the
logic to update itself fromt he model.
</quote>

This is probably the closest to what I actually implement when I write
MVC. The V directly queries the M to find out what to display, and the C
"directly" (it may receive event notifications from the widgets, which are
also part of V) manipulates the M.

So with the above clarification, I've written some moderately complex
applications using the MVC/MVP design pattern, and I didn't encounter too
many limitations or problems with it. Was there a specific problem that was
unaddressed when you tried to apply this/these patterns to your application?

- Oliver
 
C

Chris Uppal

diegomrosa said:
All I want is a Java rich client design patterns and best practices
guide.

Assuming that you are not looking for:
- a guide to the best practises and/pr gotchas of
Swing programming (e.g. being EDT-aware),
- a guide to the best practises and/or gotchas of
programming in general,
- a guide to creating high-quality user interfaces,
there doesn't seem to be much left to say:

+) Ensure that domain logic is separated from presentation logic.

+) Ensure that domain logic does not depend on any specific presentation.

+) (For bonus points) Ensure that presentation logic is composable rather than
monolithic.

I don't do much Swing programming, but as far as I am aware it has little
built-in architecural support for any of the above. OTOH, it has nothing much
that /prevents/ the above either.

Borrowing the terminology of MVC (or MVP), and calling the domain-level stuff
the model(s). One simple test for whether you've got good separation is
whether you can easily start a new presentation on the same model, or tell an
existing presentation to use a different model. Neither should take more than
a line or two of extra code.

-- chris
 
D

diegomrosa

Joined
Sep 3, 2007
Messages
1
Reaction score
0
Hi Diego

I am asking the exact same question that you are. Where can I find a good working example? IMHO one of the reasons that Swing has such a bad rap is because there is no standard framework.

Two links that might help.

http://www.javaworld.com/javaworld/jw-07-2000/jw-0721-hmvc.html?page=1
- I thought that too much logic eneded up in the view.

and http://blog.hibernate.org/cgi-bin/blosxom.cgi/Christian Bauer/java/hibernateswing.html

Neither of them are MVP but HMVC...


Do you have any other examples for me?

Richard
 
Joined
Dec 17, 2010
Messages
1
Reaction score
0
Swing MVP

Hi guys,

I know this thread is old, but thought I would make a comment. I've done a lot of Swing development and was quite frusterated with the lack of framework. There are so many options for Java EE, but not much out there for SE.

This being the case, I took up the challenge of putting together a Java MVP framework that you can use with Swing. I outline the project in my blog on Java MVP - logicdevelopment.net/blog/?p=16 The project is called Biscotti. Really clean separation of model view presenter with some add-ins for people used to doing MVP on the web.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top