4.12 Summary


4.12 Summary

The static view of a program describes the program as an assembly of classes. A class is a decomposition unit—a basic modular unit that allows breaking a problem into smaller subproblems.

A class is also a type for object reference variables. It is also a collection of objects with similar characteristics. A class is a reusable unit; it can be reused in other applications.

An algorithm is a complete, precise, detailed description of the method of solution to a problem. Because a problem is broken down into subproblems, the solution is sought for each of the subproblems. In practice, the algorithm for the complete problem is broken down and designed in each class and in each function.

The general structure of a class consists of data definitions and function definitions. A class is decomposed into data definitions and functions. Data declarations exist in the class to define the attributes; data declarations also appear in the functions to define the function's local data. A function includes data definitions and instructions.

Data definitions consist of the declarations of constants, simple variables, and object variables (references). The data declarations require the type and name of the constant, variable, and object reference. After object references are declared, the corresponding objects can be created.

The definition of classes in KJP and other object-oriented programming languages is accomplished by writing the program using the language statements and following a few rules on how to structure the program.

Two complete programs were presented in this chapter. The first program consists of two class definitions (Ball and Mball). Two objects of class Ball are created and function main sends several messages to each object.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

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