Concepts of Programming Languages

(Sean Pound) #1
12.2 Object-Oriented Programming 525

12.2 Object-Oriented Programming


12.2.1 Introduction


The concept of object-oriented programming had its roots in SIMULA 67 but
was not fully developed until the evolution of Smalltalk resulted in Smalltalk 80
(in 1980, of course). Indeed, some consider Smalltalk to be the base model for
a purely object-oriented programming language. A language that is object ori-
ented must provide support for three key language features: abstract data types,
inheritance, and dynamic binding of method calls to methods. Abstract data types
were discussed in detail in Chapter 11, so this chapter focuses on inheritance and
dynamic binding.

12.2.2 Inheritance
There has long been pressure on software developers to increase their produc-
tivity. This pressure has been intensified by the continuing reduction in the cost
of computer hardware. By the middle to late 1980s, it became apparent to many
software developers that one of the most promising opportunities for increased
productivity in their profession was in software reuse. Abstract data types, with
their encapsulation and access controls, are obviously candidates for reuse.
The problem with the reuse of abstract data types is that, in nearly all cases,
the features and capabilities of the existing type are not quite right for the new
use. The old type requires at least some minor modifications. Such modifica-
tions can be difficult, because they require the person doing the modification
to understand part, if not all, of the existing code. In many cases, the person
doing the modification is not the program’s original author. Furthermore, in
many cases, the modifications require changes to all client programs.
A second problem with programming with abstract data types is that the
type definitions are all independent and are at the same level. This design often
makes it impossible to organize a program to match the problem space being
addressed by the program. In many cases, the underlying problem has catego-
ries of objects that are related, both as siblings (being similar to each other) and
as parents and children (having a descendant relationship).
Inheritance offers a solution to both the modification problem posed
by abstract data type reuse and the program organization problem. If a new
abstract data type can inherit the data and functionality of some existing type,
and is also allowed to modify some of those entities and add new entities, reuse
is greatly facilitated without requiring changes to the reused abstract data type.
Programmers can begin with an existing abstract data type and design a modi-
fied descendant of it to fit a new problem requirement. Furthermore, inheri-
tance provides a framework for the definition of hierarchies of related classes
that can reflect the descendant relationships in the problem space.
The abstract data types in object-oriented languages, following the lead of
SIMULA 67, are usually called classes. As with instances of abstract data types,
class instances are called objects. A class that is defined through inheritance
Free download pdf