Summary

The basic purpose of a Java interface is to declare a set of methods that a class implements. This usually implies that the class provides the services that the method names suggest. An exception to this responsibility occurs when the interface lets an object register for event notification. In this situation, the client of the interface bears responsibility for calling the interface methods when the events implied by the method names occur. When you create a registration interface, it is useful to pair the interface with an abstract class that provides empty implementations of the interface methods, simplifying registration. Interfaces and classes can also collaborate in the use of constants, with interfaces providing better readability ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.