complex programs fairly easily. Structured languages are characterized by their support for
stand-alone subroutines, local variables, rich control constructs, and their lack of reliance upon
theGOTO. Although structured languages are a powerful tool, they reach their limit when a
project becomes too large.
Object-oriented programming took the best ideas of structured programming and combined
them with several new concepts. The result was a different way of organizing a program. In the
most general sense, a program can be organized in one of two ways: around its code (what is
happening) or around its data (who is being affected). Using only structured programming
techniques, programs are typically organized around code. This approach can be thought of as
"code acting on data." For example, a program written in a structured language such as C is
defined by its functions, any of which may operate on any type of data used by the program.
Object-oriented programs work the other way around. They are organized around data, with the
key principle being "data controlling access to code." In an object-oriented language, you
define the data and the routines that are permitted to act on that data. Thus, a data type defines
precisely what sort of operations can be applied to that data.
To support the principles of object-oriented programming, all OOP languages have three traits
in common: encapsulation, polymorphism, and inheritance. Let's examine each.
Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps
both safe from outside interference and misuse. In an object-oriented language, code and data
may be combined in such a way that a self-contained "black box" is created. When code and
data are linked together in this fashion, an object is created. In other words, an object is the
device that supports encapsulation. Within an object, code, data, or both may be private to that
object or public. Private code or data is known to and accessible only by another part of the
object. That is, private code or data may not be accessed by a piece of the program that exists
outside the object. When code or data is public, other parts of your program may access it even
though it is defined within an object. Typically, the public parts of an object are used to
provide a controlled interface to the private elements of the object. For all intents and purposes,
an object is a variable of a user-defined type. It may seem strange that an object that links both