Home Segments Top Top Previous Next

Chapter 20:

How to Enforce Requirements
and to Document Programs Using Interfaces

In Chapter 19, you learned how to use abstract classes to impose method-definition requirements on subclasses. In this chapter, you learn how to use Java's interface mechanism to establish method-definition requirements on a class without relying on inheritance from an abstract class.

A principle of good programming practice is that you should think about what you want your programs to do before you proceed to write them. Because establishing requirements forces you to think about what you want your programs to do, liberal use of Java's interface mechanism is good programming practice.

In this chapter, you also learn that Java's interface mechanism help teams of programmers to work together effectively, and you learn that interfaces offer splendid locations for program documentation.

Thus, Java's interface mechanism, reflectively used, can make you a much better programmer.