Best way for a Swing GUI to communicate with domain logic?


I have some domain logic implemented in a number of POJOs. I want to write a Swing user interface to allow the user to initiate and see the results of various domain actions.

What's the best pattern/framework/library for communications between the UI and the domain? This boils down into:

  • the UI being able to convert a user gesture into a domain action
  • the domain being able to send state/result information back to the UI for display purposes

I'm aware of MVC as a broad concept and have fiddled with the Observer pattern (whose Java implementation has some drawbacks if I understand correctly), but I'm wondering if there's an accepted best practise for this problem?


MVC is fantastic for an individual widget, however it gets a little unruly when you have "pages" and "forms" with lots of widgets.

One thing that might be worth looking into (and I'm not endorsing it, I haven't actually used it, just implemented something very similar for myself) is the Beans Binding Framework (JSR295)

By : Aidos

I have used the Observer pattern (using AspectJ magic) in the past with some success, but found that unless you were careful it quickly became a cluster.. uhh.. flick?

It quickly became hard to manage and most importantly extremely hard to debug.


To expand slightly on my answer, we were using SWT, not Swing, so YMMV. We basically used AspectJ to hook up the transference of data from the UI components to the model objects. These model objects were dumb POJOs.

Actual business logic was done by 'watching' the model objects with AspectJ and firing off the required event if they changed. So if you changed a value in a textbox AspectJ would fire and copy that value into a POJO. If that field in the POJO had an event on it for business logic that would then fire. If that logic modified any POJOs (and it could) AspectJ would notice and copy the value from the POJO into the UI component.

By : SCdF

Definitely MVC - something like this example which clearly splits things out. The problem with the Swing examples is that they seem to show the MVC all working within the swing stuff, which does not seem right to me

This video can help you solving your question :)
By: admin