Observer pattern

Discussion in 'C++' started by mem, May 18, 2004.

  1. mem

    mem Guest

    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!
     
    mem, May 18, 2004
    #1
    1. Advertising

  2. "mem" <> wrote in message
    news:48gqc.17957$...
    > 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
     
    John Harrison, May 18, 2004
    #2
    1. Advertising

  3. mem

    adiian

    Joined:
    Aug 22, 2006
    Messages:
    2
    adiian, Jun 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beatrice Rutger
    Replies:
    0
    Views:
    761
    Beatrice Rutger
    Jun 5, 2005
  2. Replies:
    6
    Views:
    756
    Chris Uppal
    Feb 13, 2006
  3. Paolino

    An observer pattern application.

    Paolino, Aug 18, 2005, in forum: Python
    Replies:
    0
    Views:
    354
    Paolino
    Aug 18, 2005
  4. Michael Schneider

    weakrefs to functions for observer pattern

    Michael Schneider, Nov 3, 2005, in forum: Python
    Replies:
    3
    Views:
    392
    Alex Martelli
    Nov 3, 2005
  5. Replies:
    5
    Views:
    580
Loading...

Share This Page