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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:02:05+00:00 2026-06-09T18:02:05+00:00

I’m trying to get my head around observer pattern, and conceptually – I get

  • 0

I’m trying to get my head around observer pattern, and conceptually – I get it, it seems REALLY beneficial for lots of stuff…

however… in all the examples and reading I’m doing – it seems all the examples use a “single” data point, and a single class to manage that data point, so of course if ‘x’ changes, notify some other (registered) class…

what does one do when there are multiple methods in a class that MAY change multiple data points? – are the “observers” supposed to register for a specific ‘method’ – or do you add an ‘onchange’ method –

Take for example a USER object, with some normal CRUD methods, ‘insert’, ‘update’, ‘delete’… each of those methods ‘changes’ the data.

if I have 2 observers – an ‘logging’ object, and a UI object ties to the username… clearly the logging object will want to know about ANY of the data changing while the UI object may only care about the username.

how does one handle these multiple data points – you would (hopefully) NOT write your code to update EACH data point separately – and register to ‘watch’ each !!! that’ would be ridiculous.

For arguments sake – assume the ‘attributes’ of user are 100 data points – (first,middle,last,dob,username,email,password,lastlogin,etc…) and an “updateUser” method fires – changing ONLY the lastlogin… does the ‘notification’ handle the conditional logic that decides NOT to alert the UI – or is the UI alerted (as it’s an observer of ‘user’ – and the UI object has a method to handle notification, and IT does the conditional logic to decide that ‘lastlogin’ doesn’t interest 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-06-09T18:02:07+00:00Added an answer on June 9, 2026 at 6:02 pm

    You don’t have to register your observers for every method. You can categorize your observers, for example:

     private Observer[] updateObservers;
     private Observer[] usernameUpdateObservers;
    

    When an observer registers itself, it has to know what group to put itself in. Then your User class will notify the appropriate groups;

      public void setUsername(String username) {
        this.username = username;
        notify(updateObservers);
        notify(usernameUpdateObservers);
      }
    
      public void setEmail(String email) {
        this.email = email;
        notify(updateObservers);
      }
    

    However, when you are observing every action of an object, a Proxy might be a better fit. I’ll give you a little java example (now there are ways to do this in java dynamically, but to illustrate the point, here’s the long version).

     public interface User {
       void setUsername(String username);
       void setEmail(String email);
     }
    
     public class LoggingUserProxy implements User {
       private User user;
    
       public LoggingUserProxy(User user) { this.user = user; }
    
       public void setUsername(String username) {
         user.setUsername(username);
         log("updated username to " + username);
       }
    
       public void setEmail(String email) {
         user.setEmail(email);
         log("updated emailto " + email);
       }
    

    Now when I create my user, I wrap it in the proxy

       User user = new LoggingUserProxy(realUser);
    

    The interface is unchanged and your User object is not polluted with all of the notify() calls.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.