O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required