1

I want to keep my business logic behind an interface (which is a good practice, I understand). I also want the business logic to be Observable, and Observable is a concrete class.

The other parts of the program need to know that the business logic both 1) implements my own interface, and 2) extends the Observable. And I need both, every time.

How do I do that?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hessu
  • 11
  • 2
  • check the example http://www.coderanch.com/t/380786/java/java/Observable-class-Observer-interface – Sajith Sep 08 '12 at 08:38

2 Answers2

3
public abstract class MyObservable extends Observable implements MyInterface {}
user207421
  • 305,947
  • 44
  • 307
  • 483
  • Btw , maybe it will helpful in this context : [abstract class can implement an interface without overriding all the methods](http://stackoverflow.com/questions/197893/why-an-abstract-class-implementing-an-interface-can-miss-the-declaration-impleme) – MD. Sahib Bin Mahboob Sep 08 '12 at 09:08
  • @MD.SahibBinMahboob Trick? It's just the answer to the question. Pretty obvious really. Your link doesn't say anything that the word `abstract` doesn't already say. – user207421 Sep 08 '12 at 09:39
  • yup , but i found it helpful for me as i did not know it explicitly. I thought it will be helpful for bargainer like me :) – MD. Sahib Bin Mahboob Sep 08 '12 at 10:18
1

Rather than using an interface for your interface use an abstract class that extends Observable.

public abstract class MyType extends Observable {
    public abstract void doSomething();
    ...
}
Tom
  • 43,583
  • 4
  • 41
  • 61