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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:16:46+00:00 2026-05-26T19:16:46+00:00

I have the following notification sent for an Observer and Observable design pattern private

  • 0

I have the following notification sent for an Observer and Observable design pattern

private void changeEnvironment()
    {
        Random random = new Random();
        season = SEASON[random.nextInt(3)];
        dayInTime = DAY_IN_TIME[random.nextInt(2)];
        temperature = random.nextInt(120);
        setChanged();
        notifyObservers(season);
        notifyObservers(dayInTime);
        notifyObservers(temperature);
    }

However, in my:

public void update(Observable o, Object arg) {

    }

How do I check whether it’s season, dayInTime, or temperature?

  • 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-26T19:16:47+00:00Added an answer on May 26, 2026 at 7:16 pm

    You can use the observer pattern in pull mode , which means that observable will pass itself to the observer ‘s update() .So , observer can get properties they want from the observable ‘s getters.

    I assume temperature, dayInTime , season in your subject are both int

    So , you Observable (i.e Subject) will looks like :

    public class Subject extends Observable{
    
        private int temperature;
        private int dayInTime;
        private int season;
    
        private void changeEnvironment() {
            Random random = new Random();
            this.season = SEASON[random.nextInt(3)];
            this.dayInTime = DAY_IN_TIME[random.nextInt(2)];
            this.temperature = random.nextInt(120);
            setChanged();
    
             /** Notify all of the subscribed observers about its changes
              It will call each observers' update(this, null)***/
            notifyObservers();
        }
    
    
        public int getTemperature(){....}
        public int getdayInTime(){.....}
        public int getSeason(){....}
    
    }
    

    Then your observer can get temperature, dayInTime , season by using the corresponding getters of your Observable :

    public void update(Observable o, Object arg) {
    
       Subject = (Subject) o;
       int temperature = o.getTemperature();
       int dayInTime= o.getdayInTime();
       int season= o.getSeason();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined the following service with an observer of messages sent. The problem
I have following classes. class A { public: void fun(); } class B: public
I have created an application that creates notifications, using the following code: // notification
I have to create a WCF service that handles following tasks: Register the notification
I have the following problem, related to the Apple Push Notification service on iPhone:
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party

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.