Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This article has left me a little confused.

In explaining a method on how to design MVC into Java Swing apps the author defines the controller class as Singleton and relays a series of calls to the Controller for each operation.

In a view object:


And inside the controller class:

public void processForm() {
    result1 = doSomethingWithName(this.nameTextField.getText());
    result2 = doSomethingWithEmail(this.emailTextField.getText());
    this.owner.setResult(result1, result2);

I don't understand why this has been made so complex! Wouldn't it be simpler, less error prone and more modular to simply:

Controller.processForm(this, this.nameTextField.getText(), this.emailTextField.getText());


public static void processForm(OwnerClass owner, String name, String email) {
    result1 = doSomethingWithName(name);
    result2 = doSomethingWithEmail(email);
    this.owner.setResult(result1, result2);

Is anyone familiar with this design pattern? Is there reason to this method?

share|improve this question

It's been a long time ago since I last used an MVC approach in Swing, but I immediately notice some things I wouldn't do.

  1. Don't use a singleton, singletons are evil!
  2. Passing view components to the controller? When I do MVC, I tend to pass the controller to my view elements, preferably just an interface. The view can request actions on the controller. This allows for total decoupling of the view. So you can also switch to something else than Swing. This probably isn't the 'default' approach of MVC with Swing however.

So yeah, it seems I would agree with you. Perhaps try looking for other MVC examples with Swing. This article doesn't look particularly appealing IMHO.

share|improve this answer
Singletons, I thought, were only evil if they held state. This one doesn't. Is it that bad? – Pureferret Apr 9 '13 at 11:01

I agree with steven concerning Singletons. I think the most convenient way to call something like this is a builder-pattern-like approach ("fluent interfaces") similar to StringBuilder:


This is Java's closest approximation of named and default arguments in other languages (e.g. you don't have to remember the order of parameters, you can make some of them optional, and with a little type trickery you can ensure that processForm can be only called if all mandatory args are set).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.