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 8040101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:47:08+00:00 2026-06-05T03:47:08+00:00

I have a basic MVC pattern created in Java that uses the Observable/Observer class/interface.

  • 0

I have a basic MVC pattern created in Java that uses the Observable/Observer class/interface.

Observable    Observer      Observable/Observer
Model         Controller    View

View triggers an event to the Controller, when the user interacts with the GUI.
- E.g presses a button, fills in a field, etc.

Model triggers an event to the View when it updates its state.
- E.g when the a button was pressed and the Controller requests new results.

My question is about the Observer function

update(Observable obs, Object arg);

This is one function, but I have many different kinds of updating to do in my View for example. How do I elegantly distinguish between an update to, say, my search results or the displaying of additional information? These are two completely different updates that use different objects from the Model.

My first idea was to use the Object to pass a string which would describe what update is required.

"UpdateResults" "DisplayAdditionalInformation" "AddQuestions"

but that seems error-prone and ugly. My second instinct was to create an EventObject that would be passed as an Object, but then I have to keep asking what kind of EventObject I’m using:

if (arg instanceof ResultEventObject) 
    // Get results from model
else if (arg instanceof InformationEventObject)
    // Get information from model
else if (arg instanceof QuestionsEventObject)
    // get questions from model

My third idea is to simply update everything, but that seems pointlessly inefficient.

I am probably not understanding the Observable/Observer interface correctly or I’m not using update() as it was intended by it’s authors. Therefore my question, how do I use the updatefunction properly when I have many different types of updates or events to process?

  • 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-06-05T03:47:10+00:00Added an answer on June 5, 2026 at 3:47 am

    You can create your own Listener interfaces depending on what view/model you are listening to. This allows your view/model to pass exactly the information required to your controller and will make it easier to unit test the controller.

    For listening to the model, updating everything is the simplest solution and you can do that unless performance proves to be an issue.

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

Sidebar

Related Questions

I have a basic MVC view model with annotations, for example: [Required(ErrorMessage=Your Name Required)]
I have a basic Spring MVC controller that looks like this: @Controller public void
I have basic knowledge of Java and some experience with MVC pattern. I have
I am new to MVC and have a grasp of the basic model, but
I have a basic class that derived subclasses inherit from, it carries the basic
I have a basic ASP.NET MVC 3 app. I have a basic action that
I have a very basic question about MVC web applications in Java. Since the
i'm trying to implement a basic mvc pattern for a java web app project
I just started to study the Model View Controller pattern. I now understand the
I have looked at Spring MVC a few times briefly, and got the basic

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.