Chapter 23. Generic Class Libraries


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 ”

  • Analyzing the problem

  • Example: least squares fit

  • Implementing the generic part

  • Implementing the problem-specific part

  • Testing the generic class library



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net