5.2 Classes


5.2 Classes

In Chapter 3, the model of an object is described as an encapsulation of the attributes and behavior into a single unit. When access to some of the attributes and some operations is not allowed, the access is said to be private; otherwise, the access mode is public. This is considered an encapsulation protection mechanism.

A class defines the attributes and behavior of the objects in a collection. In other words, every collection of entities is defined by describing the attributes and behavior of these entities. The attributes are defined as data declarations, and the behavior is defined as one or more operations (methods or functions). As an example, Figure 5.1 shows the general structure of a class.


Figure 5.1: General structure of a class named Class_A.

Applying the principle of information hiding, knowledge about an object is limited; only the knowledge necessary for the features of an object to be accessed by another object is made available. The rest of the knowledge about the object is not revealed. The internal details of how the various operations are carried out are not made available to other objects.

If a function of an object is public, it is accessible from another object; the implementation details are kept hidden. In general, only the function headers (also known as function specifications) are known to other objects.

The software definition of a class consists of:

  • The data declaration of the attributes of the class

  • A set of method or function definitions




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