Java interfaces describe types (as defined in Design Patterns). The limiting factor in Java interfaces is that you cannot declare the instance variable needed for your observer list.
This is where the abstract class comes in. You can declare an instance variable as follows:
import java.util.List; public abstract class Subject { List<Observer> observers;
However, interfaces are better because they are better at forcing encapsulation. You can add another layer of abstraction by declaring three methods in an interface, which in turn declares these methods / "types". Then an abstract class can implement these methods. Of course, any class that extends an abstract class will not have to implement the attachObserver and detachObserver methods.
source share