What Is Object-Oriented Programming?
Since object-oriented
programming (OOP) drove the creation of C++, it is necessary to understand its foundational
principles. OOP is a powerful way to approach the job of programming. Programming
methodologies have changed dramatically since the invention of the computer, primarily
to accommodate the increasing complexity of programs. For example, when computers
were first invented, programming was done by toggling in the binary machine instructions
using the computer's front panel. As long as programs were just a few hundred instructions
long, this approach worked. As programs grew, assembly language was invented so
that a programmer could deal with larger, increasingly complex programs, using symbolic
representations of the machine instructions. As programs continued to grow, high-level
languages were introduced that gave the programmer more tools with which to handle
complexity. The first wide spread language was, of course, FORTRAN. Although FORTRAN
was a very impressive first step, it is hardly a language that encourages clear,
easy-to-understand programs.
The1960 s gave birth to
structured programming. This is the method encouraged by languages such a C and
Pascal. The use of structured languages made it possible to write moderately 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 the GOTO. Although structured languages area powerful
tool, even 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 a round 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.
0 comments:
Post a Comment