LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2012, 07:10 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Observer pattern-The subject keeps track of the items to be observed by the observer


Observer pattern-
Assumption:
  • Out of the 10 items, the observer only wants to be subscribed to 3.
  • Subject calls a function of the observer to let him know that there are some updates.

Now, is it subject's responsibility to send the updates pertaining to only 3 items to the observer?
OR
Subject can simply tell the observer that there are updates - go and fetch whichever you want out of 10?

Which is the correct way out? Does it matter?

Last edited by Aquarius_Girl; 05-02-2012 at 07:29 AM.
 
Old 05-02-2012, 08:51 AM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by Anisha Kaul View Post
Observer pattern-
Assumption:
  • Out of the 10 items, the observer only wants to be subscribed to 3.
  • Subject calls a function of the observer to let him know that there are some updates.

Now, is it subject's responsibility to send the updates pertaining to only 3 items to the observer?
OR
Subject can simply tell the observer that there are updates - go and fetch whichever you want out of 10?

Which is the correct way out? Does it matter?
There is no right answer.

The most appropriate action is to fulfill whatever the observer was promised at the time he/she subscribed.

Daniel B. Martin
 
Old 05-02-2012, 08:53 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,275

Rep: Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342Reputation: 5342
Either let the observer choose which items to subscribe to, or send all 10 item updates to the observer. Which one is "best" depends on which will ultimately give you simpler code. (And probably on the nature of the data being passed).

Last edited by dugan; 05-02-2012 at 08:56 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing Observer pattern when observers wish to observe different items Aquarius_Girl Programming 2 05-02-2012 09:27 AM
Observer added ??? Chikne Slackware 1 11-25-2006 03:09 AM
new observer emarald LinuxQuestions.org Member Intro 1 05-03-2006 03:09 PM
page observer delos Linux - Software 2 01-25-2005 07:35 AM
need some advice on c++ observer design pattern digitized_funk Programming 1 11-13-2003 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration