Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Observer pattern

Reply
Thread Tools

Observer pattern

 
 
mem
Guest
Posts: n/a
 
      05-18-2004
Class subject
{
private:
List<Observer*> *_observers;
....
};

Why use a pointer, _observers, above?

Is it really necessary to have Subject and Observer base classes in the
pattern? Instead, just pass a pointer of a class into another, and the
latter just informs the former by calling its member function, whenever
needed?

How to assign _observers to a List object?

Thanks!


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-18-2004

"mem" <(E-Mail Removed)> wrote in message
news:48gqc.17957$(E-Mail Removed)...
> Class subject
> {
> private:
> List<Observer*> *_observers;
> ...
> };
>
> Why use a pointer, _observers, above?


Why indeed? I can't think of a good reason.

>
> Is it really necessary to have Subject and Observer base classes in the
> pattern? Instead, just pass a pointer of a class into another, and the
> latter just informs the former by calling its member function, whenever
> needed?


How would you deal with pointers to different classes? How you you write a
list that can take an arbitary pointer and call use that pointer to call
specific member functions.

>
> How to assign _observers to a List object?
>


That question makes no sense to me. Do you mean 'how to add an observer to
the _observers list?'. The answer to that would be use the appropriate
method of the List class.

john


 
Reply With Quote
 
 
 
 
adiian adiian is offline
Junior Member
Join Date: Aug 2006
Posts: 2
 
      06-04-2007
Observers are really necessary. Just imagine you need to add another observer. You just derive from base observer class and that's it, no need to change existing classes. You can live without subjects but what to do when you need to add a new one?

see http://www.oodesign.com/oo_design_pa...r_pattern.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions about the observer pattern samir.vds@googlemail.com Java 5 10-01-2006 07:07 PM
Observer pattern issue cstratelos@gmail.com Java 6 02-13-2006 12:43 PM
weakrefs to functions for observer pattern Michael Schneider Python 3 11-03-2005 03:24 PM
An observer pattern application. Paolino Python 0 08-18-2005 08:24 AM
JMS or MVC (Observer pattern) in lightweight front end? Beatrice Rutger Java 0 06-05-2005 04:27 PM



Advertisments