Java Reference
In-Depth Information
387
Chapter 9 Interfaces and Polymorphism
C HAPTER G OALS
ȗ
To learn about interfaces
ȗ
To be able to convert between class and interface references
ȗ
To understand the concept of polymorphism
ȗ
To appreciate how interfaces can be used to decouple classes
ȗ
To learn how to implement helper classes as inner classes
ȗ
To understand how inner classes access variables from the surrounding scope
G To implement event listeners in graphical applications
In order to increase programming productivity, we want to be able to reuse software
components in multiple projects. However, some adaptations are often required to
make reuse possible. In this chapter, you will learn an important strategy for
separating the reusable part of a computation from the parts that vary in each reuse
scenario. The reusable part invokes methods of an interface. It is combined with a
class that implements the interface methods. To produce a different application, you
simply plug in another class that implements the same methods. The program's
behavior varies according to the class that was plugged inȌthis phenomenon is
called polymorphism.
387
388
9.1 Using Interfaces for Code Reuse
It is often possible to make code more general and more reusable by focusing on the
essential operations that are carried out. Interface types are used to express these
common operations.
Use interface types to make code more reusable.
Search WWH ::




Custom Search