4.4 Classes as Modules


4.4 Classes as Modules

In object-oriented modeling and programming, there are various levels of modularity. Modules can be packages or classes. A package is a grouping of classes, and a class consists of one or more operations or functions.

An object-oriented program contains one or more classes, and each class defines a collection of similar objects. Therefore, from the static view, a program is an assembly of classes. For example, Figure 4.2 shows a program with four classes. The four classes are Class_A, Class_B, Class_C, and Class_D. This just illustrates that any object-oriented program is decomposed into one or more classes.

As explained before, a class defines the structure and the behavior of the objects in that class. The software definition of a class consists of:

  • Descriptions of the data, which are the attribute declarations of the class

  • Descriptions of the operations or functions of the class

Note

The most important decomposition unit in an application is the class, which can be considered a module that can be reused in another application.

Data descriptions represent the declarations of the attributes for the objects of the class. Descriptions of the operations represent the behavior for the objects of the class. Figure 4.3 illustrates the structure of a class named Class_A. This class consists of the declarations of the attributes and the definitions of three operations: Operation1, Operation2, and Operation3. Each of these operations consists of its local data declarations and its instructions.


Figure 4.3: General structure of a class named Class_A.

An operation, also known as a function or method, is the smallest modular unit; it carries out a single task. Functions are not standalone units because every function belongs to a class; a function is an internal decomposition unit.




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