Java Reference
In-Depth Information
Figure 27.6. You can apply Decorator to create and to plot new functions without
introducing new classes.
Most of the classes in the Function hierarchy work by wrapping their namesake function
around another function that they receive in a constructor. The Function class holds an
array of "sources," the source functions that each instance of a subclass will wrap:
package com.oozinoz.function;
public abstract class Function
{
protected Function[] source;
public Function(Function[] source)
{
this.source = source;
}
public Function(Function f)
{
this(new Function[] {f});
}
public abstract double f(double t);
}
Most Function subclasses wrap a single function. Consider the code for Abs.java :
package com.oozinoz.function;
public class Abs extends Function
{
public Abs(Function f)
{
super(f);
}
public double f(double t)
{
return Math.abs(source[0].f(t));
}
}
Search WWH ::




Custom Search