



|
|
CS1 Course Site
|
Class Notes
Wednesday October 11 , 2000
|
|
|
Definition
The FUNCTIONAL APPLICATION ARCHITECTURE is the application architecture in which:
- all variable reference in a method are declared local to the method
- all methods defined in the class, with the notable exception of ``main, '' are operators
The ``functional'' approach....
class
static public void main (String args [])
{
double figureArea = readFigureArea ();
int nrSquares = readNrOfSquares ();
double squareArea = computeSquareArea
(figureArea, nrSquares);
double squareSide = computeSquareSide
(squareArea);
int eeCount = computeEECount (nrSquares);
double perimeter = computePerimeter
(squareSide, eeCount);
IO.println (``Perimeter = ``+ perimeter);
}
/ /End of main method
static private double readFigureArea ()
{
IO.print (``Total figure area? ``);
return IO.read_double ();
}
static private int readNrOfSquares ()
{
IO.print (``How many squares? ``);
int nrOfSquares = IO.read_int ();
return nrOfSquares;
}
static private double computeSquareArea
(double totalArea, int nrSquares)
{
double sa = totalArea /nrSquares;
return sa;
}
static private double computeSquareSide
(double areaOfSquare)
{
return Math.sqrt (areaOfSquare);
}
static private int compute eeCount (int ns)
{
return (ns * 2) + 2;
}
static private double perimeter
(double s, int eeCount)
{
return s * eeCount;
}
|
Definition
The OBJECTIVE APPLICATION ARCHITECTURE is the application architecture in which the ``perfect'' object for solving the problem at hand is created from a specially tailored class.
The ``objective'' solution to the line of squares problem....
class LineOfSquares
static public void main (String args [])
{
LineOfSquares los = new LineOfSquares ();
double p = los.perimeter ();
IO.println (``Perimeter is ``+ p);
}
/ /Instance variables
private int nrSquares;
private double edgeLength;
/ /Constructor
public LineOfSquares ()
{
IO.print (``How many squares? ``);
nrSquares = IO.read_int ();
IO.print (``Area of figure? ``);
double areaOfFigure = IO.read_double ();
double areaOfSquare = areaOfFigure /nrSquares;
edgeLength = Math.sqrt (areaOfSquare);
}
public double perimeter ()
{
return edgeLength * eeCount ();
}
private int eeCount ()
{
return (nrSquares * 2) + 2;
}
/ /End LineOfSquares
|
|
|