5.9 Summary


5.9 Summary

Two levels of program decomposition are discussed in this chapter, classes and functions. Classes are modular units that can be reused (in other applications), whereas functions are internal decomposition units. Most often, the function call depends on the manner in which messages are sent among objects.

Simple functions do not involve data transfer between the calling function and the called function. Value-returning functions return a value to the calling function; these functions have an associated type that corresponds to the return value. The third type of function is the one that defines one or more parameters. These are values sent by the calling function and used as input in the called function.

Other categories of functions group functions as accessor and mutator functions. The first group of functions access and return the value of some attribute of the object. The second group changes some of the attributes of the object.

Initializer functions are also known as constructors and are special functions that set the attributes to appropriate values when an object is created. A default initializer function sets the value of the attributes of an object to default values.

A complete program is included in this chapter. The program consists of two classes, Person and Mperson. Two objects of class Person are created, and then these are manipulated by invoking their functions.

Static variables and methods are associated with the class that defined them and not with its objects. The value of a static variable is shared by all objects of the class.




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