Você está na página 1de 4

Unstructured Programming

Usually, people start learning programming by writing small and simple programs consisting
only of one main program. Here ``main program'' stands for a sequence of commands or
statements which modify data which is global throughout the whole program. We can
illustrate this as shown in the following figure.

Unstructured programming: The main program directly operates on global data.


As you should all know, this programming techniques provide tremendous disadvantages
once the program gets sufficiently large. For example, if the same statement sequence is
needed at different locations within the program, the sequence must be copied. This has lead
to the idea to extract these sequences, name them and offering a technique to call and return
from these procedures.

Procedural Programming
With procedural programming you are able to combine returning sequences of statements
into one single place. A procedure call is used to invoke the procedure. After the sequence is
processed, flow of control proceeds right after the position where the call was made.

Execution of procedures: After processing flow of controls


Proceed where the call was made
With introducing parameters as well as procedures of procedures ( subprocedures) programs
can now be written more structured and error free. For example, if a procedure is correct,
every time it is used it produces correct results. Consequently, in cases of errors you can
narrow your search to those places which are not proven to be correct.

Now a program can be viewed as a sequence of procedure calls. The main program is
responsible to pass data to the individual calls, the data is processed by the procedures and,
once the program has finished, the resulting data is presented. Thus, the flow of data can be
illustrated as a hierarchical graph, a tree, as shown in the following figure for a program with
no subprocedures.
Procedural programming: The main program coordinates calls to procedures
and hands over appropriate data as parameters
To sum up: Now we have a single program which is devided into small pieces called
procedures. To enable usage of general procedures or groups of procedures also in other
programs, they must be separately available. For that reason, modular programming allows
grouping of procedures into modules.

Modular Programming
With modular programming procedures of a common functionality are grouped together into
separate modules. A program therefore no longer consists of only one single part. It is now
devided into several smaller parts which interact through procedure calls and which form the
whole program.

Modular programming: The main program coordinates calls to procedures in


separate modules and hands over appropriate data as parameters
Each module can have its own data. This allows each module to manage an internal state
which is modified by calls to procedures of this module. However, there is only one state per
module and each module exists at most once in the whole program.

Object-Oriented Programming
A type of programming in which programmers define not only the data type of a data
structure, but also the types of operations (functions) that can be applied to the data structure.
In this way, the data structure becomes an object that includes both data and functions. In
addition, programmers can create relationships between one object and another. For example,
objects can inherit characteristics from other objects.

One of the principal advantages of object-oriented programming techniques over other


programming techniques is that they enable programmers to create modules that do not need
to be changed when a new type of object is added. A programmer can simply create a new
object that inherits many of its features from existing objects. This makes object-oriented
programs easier to modify.

To perform object-oriented programming, one needs an object-oriented programming


language (OOPL). Java, C++ and Smalltalk are three of the more popular languages, and
there are also object-oriented versions of Pascal.

Object-oriented programming solves some of the problems that are encountered by the
programmer in the other techniques. In contrast to the other techniques, we now have a web
of interacting objects, each house-keeping its own state.

Object-oriented programming: Objects of the program interact by


sending messages to each other
Some authors describe object-oriented programming as programming abstract data types and
their relationships.
Little program (say, 1000 lines) can be written in anything, anyhow. If you don't quit easy,
you'll make it work, at the end. But, large program is a different story. If you don't use
techniques of "good programming" (especially OOP), new errors will emerge as fast as you
fix the old ones.

Reason for this is: every part of program depends on large number of other parts, but these
dependencies are so complicated and non-intuitive, even programmer who wrote a program
can't follow them. When you change one part, you can't easily see all implications on the rest
of the program. Of course, by well-used procedural programming, it's possible to modularize
program and extract reusable code, but if you do that - you are already starting to think
object-oriented. The only thing you miss, at this point, is better way to organize a number of
procedures or functions that you already wrote, and link them with data structures they
manipulate with.

You might ask: So what? Isn't this just a more fancier modular programming technique? You
were right, if this would be all about object-orientation. Fortunately, it is not. In the next
sections, additional features of object-orientation are introduced which makes object-oriented
programming to a new programming technique.

Você também pode gostar