Item 20: Prefer interfaces to abstract classes


  • Existing classes can easily be reconstructed to implement a new interface. You just need to use implements clause to the class declaration and add the required methods
  • Interfaces are ideal for defining mixins (Example:
  • Interfaces allow for the construction of non-hierarchical type frameworks. They are great for organizing things that don’t fall into a hierarchy
  • Interfaces enable safe, powerful functionality enhancements via the wrapper class idiom (Item 18). If you use abstract classes, a programmer should use the inheritance. The resulting classes are less powerful and more fragile

Skeletal implementation class

You can combine the advantages of interfaces and abstract classes using Skeletal implementation class. You can check the following links for more information:

Leave a Reply

Your email address will not be published. Required fields are marked *