Collection classes in Java: Why arent they Observable?

Discussion in 'Java' started by shafik@u.arizona.edu, Mar 28, 2005.

  1. Guest

    Hello folks,

    Im not sure if this was pondered before or not. But why wouldnt you
    have the Collection classes be observable, i.e. you can attach
    listeners to them that listen to a state change in the collection (add,
    remove, etc). Wouldnt that make sense?


    --Shafik
    , Mar 28, 2005
    #1
    1. Advertising

  2. wrote:

    > Im not sure if this was pondered before or not. But why wouldnt you
    > have the Collection classes be observable, i.e. you can attach
    > listeners to them that listen to a state change in the collection (add,
    > remove, etc). Wouldnt that make sense?


    That might be a useful thing to do under certain special circumstances,
    in which case it is relatively easy to roll your own wrapper around
    existing collections to make it happen. In general, however, this kind
    of behavior is rarely desired, and it does involve some overhead even
    when there are no observers registered.

    Perhaps a better explanation OO-wise is that being observable is not
    central to being a Collection. As such, it would *not* have made sense
    to make all Collections Observable, no matter how convenient you might
    find it at the moment.

    --
    John Bollinger
    John C. Bollinger, Mar 28, 2005
    #2
    1. Advertising

  3. Ian Shef Guest

    "" <> wrote in
    news::

    > Hello folks,
    >
    > Im not sure if this was pondered before or not. But why wouldnt you
    > have the Collection classes be observable, i.e. you can attach
    > listeners to them that listen to a state change in the collection (add,
    > remove, etc). Wouldnt that make sense?
    >
    >
    > --Shafik
    >
    >


    Unfortunately, Observable is a class, not an interface.
    Perhaps a wrapper could be set up, similar to the way that List
    synchronization is handled:

    List list = Collections.synchronizedList(new ArrayList(...));

    .... or you could provide extensions of the Collections classes that contain
    an Observable and do the right thing.


    --
    Ian Shef 805/F6 * These are my personal opinions
    Raytheon Company * and not those of my employer.
    PO Box 11337 *
    Tucson, AZ 85734-1337 *
    Ian Shef, Apr 20, 2005
    #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. Replies:
    5
    Views:
    675
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,840
    Smokey Grindel
    Dec 2, 2006
  3. Jason Cavett
    Replies:
    1
    Views:
    507
    Tom Hawtin
    Apr 19, 2007
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    965
    Øyvind Isaksen
    May 18, 2007
  5. Andy B

    textbox values arent showing up?

    Andy B, Jan 25, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    375
    Jignesh
    Jan 25, 2008
Loading...

Share This Page