Consider the following common programming situation. You write an analysis method where part of the analysis is generic and part is specific to a given problem. As a good Java programmer, you don't want a different version of the method for every problem it might be used to solve. What you want is to write one generic version of the method that accepts the problem-specific information as an argument. In C the answer would be to use a function pointer . As the name implies, it is a pointer to a generic function with a certain input parameter list. Java doesn't have function pointers, but you can do the same thing by using classes. A class can be defined to contain problem-specific information. An instance of the class is then passed to the generic analysis tool. A collection of generic analysis tools is called a generic class library. You may not have realized it, but we created a generic class library in Chapters 20, 21, and 22. In Chapter 20, the ODE solver methods integrated a generic ordinary differential equation. Information about the specific ODE to be solved was encapsulated in an instance of the ODE class that was passed to the ODE solver method as an argument. Among other things, the ODE object defined a method named getFunction() that computed the right-hand side of the ordinary differential equations being solved. In this chapter we will formalize the process for developing a generic class library using as an example the development of a method to compute a least squares curve fit to a collection of data. The specific topics we will discuss are ”
|