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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:30:11+00:00 2026-05-20T16:30:11+00:00

If an Observable object notifies its Observers when one or more of the variables

  • 0

If an Observable object notifies its Observers when one or more of the variables (animals) below is assigned to a new animal, is this an improper use of the Observer Pattern since the Observer will end up setting all four animals when only a subset of them have changed? If so, how could this be fixed? Also, how could an interface be constructed that would specify that the Observer is to set those specific animals and that the Observable is to notify the Observers if those animals are changed? Thanks in advance.


public class ObserverClass implements Observer {
    public void update(Observable o, Object o1) {
        setHippo(o.getHippo());
        setBassetHound(o.getBassetHound);
        setOstrich(o.getOstrich());
        setAntelope((o.getAntelope());
    }
}

  • 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-20T16:30:12+00:00Added an answer on May 20, 2026 at 4:30 pm
    • Updating only a subset

    Most of the time, it is not a problem, there are few instructions that will just refresh the values.
    However, if you want to update a subset, you should use the second argument of update and set it to a discriminant that will tell what to update. For this you may use a set of the types of objects that have changed.

    • Observing specific animals

    Often, you will just begin the code of your observer by if (!should_observe(x)) return; where should_observe tells whether the object will be observed.

    The other way of doing it is to create an observable that will be an oberver.
    A quick example is easier to understand:

    public class OvervableAnimal extends Observable implement Observer {
      private Class<?> animal;
      // constructor omitted
      public synchronized void update(Observable o, Object arg) {
        if (!animal.isInstance(arg))
          return; // not the right animal
        setChanged();
        notifyObservers(arg);
      }
    }
    ObserverClass obs;
    ObserverAnimal obsHippo = new ObservableAnimal(Hippo.class);
    obs.addObserver(obsHippo);
    // use obsHippo if you want to be notified when a hippo has changed
    

    Sometimes it is easier to reimplement entirely the observer pattern: it gives you more control and your observable may be an interface so you won’t need to subtype.

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

Sidebar

Related Questions

You have a pull-oriented Observable/Listenable which notifies Observers/Listeners when some state changes. The state
With a DataGrid object in WPF, we can bind its rows to an observable
I have this problem when i try to synchronize a observable list with listbox/view
Do properties on an object within an Observable collection require a PropertyChangedEvent? For example:
I am designing a viewmodel object in knockout that has an observable array. When
I have an INotifyPropertyChanged object, Foo. I turn Foo into an observable stream of
This question relates to selected object pattern with knockout Thanks to the answer, I
I have a datagrid with an Observable Collection of a custom object. The selectedItem
So I've got an object that has an observable collection. Most places I bind
addListener[FooEvent] { e => println(Got a FooEvent) } dispatchEvent(new FooEvent()) Is this even possible?

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.