Java: GUI Structural Patterns

Structuring the program - Separating the Model

In all ways of structuring a GUI program, there is one vitally important issue -- separating the code which is the essence of the problem from the user interface. This logical part is variously referred to as the model, business logic, abstraction, or document. This code must not refer to the user interface directly -- it will interact with the user interface code by returning values or invoking listeners.

Motivation. There are two compelling reasons for this separation.

  1. Lower complexity -- Programs end up being less complex and therefore easier (cheaper) to modify. For the smallest programs this may not be obvious, but the benefits show up very quickly as a program grows. This is not an advantage only in large programs.
  2. Interface Flexibility -- This allows changes to the user interface, eg, moving from Swing to SWT, or to a web interface. You should be able to use your basic logic code (if applicable) with the following interfaces.

Well-Known Patterns

MVC - Model-View-Controller Pattern
This classic pattern is widely used, altho the Presentation-Document pattern below is a more common (because it's simpler) choice for small programs.
Presentation-Document Pattern
This pattern is perhaps the best choice for small GUI applications.
PAC - Presentation-Abstraction-Control Pattern
This is the application of stepwise refinement to GUIs. Parts of the GUI are each implemented as in MVC, and these parts are put together using MVC. This is basically a recursively applied MVC model. It would only be used for complicated GUIs.