Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3968624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:51:56+00:00 2026-05-20T03:51:56+00:00

Is there an object-oriented GUI design that would be a reasonable combination of the

  • 0

Is there an object-oriented GUI design that would be a reasonable combination of the Command and Observer patterns?

My Java GUI attempts to combine Command and Observer patterns as follows:

  • the client is an observer of the Command receiver (e.g. an input GUI screen, or a dialog)
  • the invoker is an instance variable of the client
  • the update() method of the client receives the Command receiver’s input and updates the invoker with the appropriate Command

What is making me uncomfortable with this implementation is that the update() method comprises a huge number of conditional if statements.

e.g.

public class Client implements Observer {
    InputScreen inputScreen;
    Invoker director;
    InputScreenCommand inputScreenCommand;

    public Client {
        inputScreen = new InputScreen();
        inputScreen.registerObserver(this);            
        inputScreenCommand = new InputScreenCommand(inputScreen)
        director.setCommand(inputScreenCommand);
        director.invoke();
    }

    public void update(String command) {
        if (command.equals("Input Screen 2")) {
            inputScreen.removeObserver(this);
            // generate new receiver/subject
            inputScreen2.registerObserver(this);
            // generate new Command
            director.setCommand(inputScreen2Command);
            director.invoke();
        }
        // and so on through all the permutations of input from receivers
    }
}

The proper way of using the Command pattern to effectively and efficiently handle GUI events is eluding me at the moment. Is the Observer pattern a useful partner for it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:51:56+00:00Added an answer on May 20, 2026 at 3:51 am

    Well, the overall design solution for UI would be MVC, or some of it’s variations (actually, people usually leave out an explicit controller, and have a model and a view which is basically coupled with controller). Commands are not essential there, unless you want to establish an undo framework.

    In any case, if you use Java, you are likely to be stuck with a UI library (like Swing or SWT), and this library will impose a great deal of your design.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Design patterns are usually related to object oriented design. Are there design patterns for
There's some object-oriented engineering principle that states something along the lines of a class
I have: existing object oriented native code API (non GUI) GUI application that works
Are there any tools that will expand object oriented code so there is no
What object oriented design patterns do you use in your application's javascript, and why?
I want to practice solving Object oriented design problems in C++. Is there any
There have been some questions about whether or not JavaScript is an object-oriented language.
I recently read Object Oriented Exception Handling in Perl Perl.com article. Is there any
How should I implement items that are normalized in the database in object oriented
My first serious language was Java, so I have comprehended object-oriented programming in sense

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.