Adapting in the Presence of Foresight

When you need to adapt your code to meet a client's needs, you may find that the client planned for such circumstances. This is evident when the client's developers provide a Java interface that defines the services the client code needs, as in the example shown in Figure 3.1. A client class in a package makes calls to a service() method that is declared in a Java interface. Suppose that you have found an existing class with a method that can fulfill the client's needs, but the name of the method is usefulMethod(). You can adapt the existing class to meet the client's needs by writing a class that extends ExistingClass, implements ThoughtfulInterface, and overrides service() so that it delegates its requests ...

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.