Synopsis
This lecture covered application architectures including the Functional Approach to programming. Really good stuff here!
|
Definition
The FUNCTIONAL APPLICATION ARCHITECTURE is the application architecture which:
- All variables referenced in a method are declared local to the method.
- All methods are defined in the class, with the notable except of the ``main method'' are operators - they return data
The ``Functional Approach''
class -----
{
static public void main (---)
{
double figureArea = readFigureArea ();
int nrSquares = readNumberOfSquares ();
double squareArea = areaOfOneSquare (figureArea, nrSquares);
double squareSide = computeSquareSide (squareArea);
int eeCount = computeEECount (nrSquares);
double perimeter = computePerimeter (eeCount, squareSide);
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 ( ``# of 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 computeEECount (int ns)
{
return (ns * 2) + 2;
}
static private double perimeter (int eeCount, double s)
{
return s * eeCount;
}
}
|
Main Method Environment
figureArea - > 27.0
nrSquares - > 3
squareArea - > 9.0
computeSquareAreaEnvrionment
parameters:
totalArea - > 27.0
nrSquares - > 3
nrSquares is different than the one defined in the main method
local variable: sa - > 9.0
once a method terminates the data associated with it, the environment, goes away.
Definition
The OBJECTIVE APPLICATION ARCHITECTURE is the application architecture in which the ``perimeter'' object for solving the problem at hand is created from a specially tailored class.