Observer Pattern abstract vs interface

Design patterns are meant to be adapted to the particular needs of the applications; they don't prescribe rules set in stone. In particular whether something is an abstract class or an interface is for you to decide, considering all the implications that the decision has for the rest of the application.

That said, interfaces are recommended over abstract classes in general for several reasons. For example abstract classes require you to use inheritance, and in many languages you can't inherit from more than one class. If that's not a problem for your use case, go ahead and use abstract classes if you find them more convenient.


Why not just have an abstract class that implements Subject? Using interface just gives you greater flexibility. It doesn't really buy you anything to start with an abstract class. If things every change a great deal (say crossing process boundaries) then your Observable will be stuck with the abstract implementation.


In a design pattern when the word interface is used, it means the abstract API that is exposed to client component that will have different concrete implementations.

When design pattern interface maps to Java world, it could be either Java interface or a Java abstract class, and design pattern concrete class maps to a Java regular class (non-abstract).

However when making a decision you do need to understand difference between Java interface and abstract class and their purpose as well as pros and cons.

See: Interface Vs Abstract Class