Information Technology Reference
In-Depth Information
CAR
Attributes:
Color: Red
Model: Ford
TIM
Attributes:
Age: 25
Address: 300w
bellows
LION
Attributes:
Age: 10
Location: Sahara zoo
Methods:
Drive
Apply brake
Park
Methods:
Hunt
Eat
Sleep
Methods:
Walk
Eat
Sleep
Fig. 2.2
Real world objects with attributes and methods
In the next section we will discuss classes in further detail; but first, Figs. 2.1
and 2.2 provide examples of real world objects and their associated attributes and
methods.
2.2 Classes
The class-object relationship is essential to the object-oriented paradigm. The two
are intrinsically linked, and, truly, one cannot be discussed without mention of the
other. They are not, however, the same. This section defines classes and describes
the relationship and differences between classes and objects. It also explains the
distinct roles that the two concepts play in object-oriented programming.
2.2.1 Classes Versus Objects
Objects are instances of classes. It seems natural, then, to say that classes can be
thought of as parents to objects. This logic, however, misses a fundamental point
in the object-oriented paradigm. To say that classes are related to objects as parents
are related to children suggests that classes and objects are the same type of entity,
in the way that a parent and his or her child are both human beings. This is not
accurate. Rather, using the same example, a class can be thought of as the DNA of
an object. DNA is not itself a human being, but the description of a human being's
attributes. Both parents and children, on the other hand, can be thought of as
objects created according to their DNA. In short, a class is the concept behind an
object, or the ''essence'' of an object, while an object itself is a tangible entity with
a place in space and time (or system memory) (Booch 1994 ).
A second, related definition of a class is similar to the more common definition
of the word in everyday speech. In standard use, a class is a ''group, set, or kind
sharing common attributes'' (Merriam-Webster 2009 ). In object-oriented pro-
gramming, the usage is the same, but more specifically describes a group of objects
 
Search WWH ::




Custom Search