Design patterns to reduce coupling in Swing application?

The best way to reduce coupling in a GUI, I think, is to use an Event Bus. There are several existing implementations out there, including some supporting Swing specifically.

The best way to reduce coupling in a GUI, I think, is to use an Event Bus. There are several existing implementations out there, including some supporting Swing specifically. Just google for swing event bus and you'll find.

If you use Guice in your GUI, you may also want to take a look at guts-events.

Thanks, this is what I was looking for. An API to provide a messaging bus across the application. I looked at guts-event and eventbus.org.

I think I'm going to go with the later. – BillMan Jul 28 '10 at 15:09 That's fine, I have used EventBus in the past and didn't have to complain about it. However, I remember in some versions, using annotations for event consumers could leak memory; I don't know if this has been fixed in latest release.

– jfpoilpret Jul 29 '10 at 4:12.

Yes. MVC is what you have to use. Here is a very good article about MVC and Swing: java.sun.com/products/jfc/tsc/articles/a....

Another Pattern that might be interesting for you is the MVP (Model View Presenter)-Pattern. This is great for coupling views more loosely to the model. A good explanation by Todd Snyder can be found here.

As you already said your intent to use MVC , or you may be already using. Once you have seperated out data (I call it as data model layer). Now you need to apply OBSERVER pattern on these data model classes.

All the views (your ui components) using this data model are observing this model objects for any change (Via observer pattern). I hope this is what you are looking for.

MVC! Then you can use also a variant of Observer called Publish/Subscribe in order to implement the event flow inside your app.

I don't agree with the people who suggest to use Event bus, because because of code like EventBus. Subscribe(SymbolListChangeEvent. Class, this); your whole code will depend on a single event bus instance which makes it very hard to test, it is hard to find out where a specific event is used.

Instead I suggest to use interfaces to encapsulate external dependencies of a module. If you like, you can use them with the listener pattern, but generally are free to refactor everything if you like.

In the case of guts-events, Event channels are interfaces, that are injected where needed (by Guice) thus easily mockable for testing. – jfpoilpret Jul 29 '10 at 16:06 For the second point I agree, but you would have the same kind of problem with other approaches.In my experience, I have systematically kept a document (with list of events, meaning, producers and consumers) up-to-date so that maintenance is eased. – jfpoilpret Jul 29 '10 at 16:09 By the way, what approach do you suggest if you don't like the Event Bus solution?

– jfpoilpret Jul 29 '10 at 16:09 Please search eventbus.Org/confluence/pages/viewpage. Action? PageId=819222 for EventBus.

Subscribe(SymbolListChangeEvent. Class, this); IMHO this looks like a single eventbus instance. – Mike L.

Jul 29 '10 at 16:55 IIRC (but it's a long time I have used EventBus, now I'm using my own exclusively, that one is for sure based on interfaces) EventBus static singleton is just provided as a convenience but you don't really have to use it and can still use EventService interface everywhere you need. – jfpoilpret Jul 29 '10 at 17:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions