How do I make a Class extend Observable when it has extended another class too?

前端 未结 6 1786
野性不改
野性不改 2020-12-13 07:48

I am learning Java and I want to make my class into an observable class.

However I already have it extending another class.

What should I do?

6条回答
  •  悲&欢浪女
    2020-12-13 07:59

    Another option is to wrap your object in an Observable object.

    public class MyObjectObservableWrapper implements Observable {  
      private MyObject myObject;
      public MyObjectObservaleWrapper(MyObject myObject){
        this.myObject = myObject;
      }
      // interface methods here
    }
    

    This option works when the data to be used by the Observable methods is accessible through public methods of MyObject. So, it may not be suitable for all cases.

提交回复
热议问题