Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By Fubarable
  • 1 Post By Fubarable

Thread: Whats the best thing to do when you can't extend Observable?

  1. #1
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Whats the best thing to do when you can't extend Observable?

    Hi,

    I have some classes which are subclasses of my other classes, for example:

    Java Code:
    class Lion extends Animal { //but can't also extend Observable
    ...
    }
    I want to create a form to edit the object properties of my class, say "Lion Editor", so I wanted to extend Observable
    so that I could add the following Observable methods to the my class' setter methods:
    Java Code:
        //a method specific to the subclass' object properties
        public void setManeLength(int length) {
            maneLength = length;
        //  methods inherited from Observable:
        //  setChanged();
        //  notifyObservers();
        }
    Whats the best way to work around this?

    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Whats the best thing to do when you can't extend Observable?

    One way: You could simply make your own observer framework and make your Observable an interface, not a class.
    ozzyman likes this.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: Whats the best thing to do when you can't extend Observable?

    Thanks. I don't know why I didn't think of that.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Whats the best thing to do when you can't extend Observable?

    You're welcome. Another option is to use a PropertyChangeSupport and allow for addition and removal of PropertyChangeListeners.
    DarrylBurke likes this.

Similar Threads

  1. to Extend or not to Extend
    By fatabass in forum New To Java
    Replies: 4
    Last Post: 12-21-2011, 04:28 PM
  2. Observer/Observable help...
    By chyrl in forum Advanced Java
    Replies: 5
    Last Post: 01-14-2011, 04:41 PM
  3. Observable/Observer JComboBox
    By rudeboy in forum Advanced Java
    Replies: 5
    Last Post: 11-27-2010, 06:03 AM
  4. Extend Jscroll
    By cowboy in forum New To Java
    Replies: 10
    Last Post: 12-13-2009, 08:07 PM
  5. using J-classes or extend them ?
    By itaipee in forum AWT / Swing
    Replies: 1
    Last Post: 01-01-2009, 07:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •