04 Lecture Four
04 Lecture Four
5
Common Programming
Paradigms
Programming
Paradigm
Imperative Declarative
object-
Procedural Functional Logic Mathematical
oriented
6
Common Programming
Paradigms
• Imperative in which the programmer instructs the
machine how to change its state.
– Procedural (Structured) which groups instructions
into procedures.
– Object-oriented which groups instructions
together with the part of the state they operate
on.
7
Common Programming
Paradigms
• Declarative in which the programmer merely declares
properties of the desired result, but not how to compute it
– Functional in which the desired result is declared as the
value of a series of function applications. Programming
with function calls that avoid any global state.
– Logic in which the desired result is declared as the answer
to a question about a system of facts and rules.
– Mathematical in which the desired result is declared as
the solution of an optimization problem.
8
Structured
Programming
• The data and the operations on the data are
separate. Data structures are sent to procedures &
functions to be operated on.
10
Structured
Programming
• Traditional structured programming suffer
some drawbacks in creating reusable
software components:
1. The programs are made up of
functions. Functions are often not
reusable. It is very difficult to copy a
function from one program and
reuse in another program because
the function is likely to reference
the headers, global variables and
other functions. In other words,
functions are not well-encapsulated
as a self-contained reusable unit. 11
Structured
Programming
2. The procedural languages are not suitable of
high-level abstraction for solving real life
problems.
For example, C programs uses constructs such as
if-else, for-loop, array, function, pointer, which
are low-level and hard to abstract real problems
such as a Customer Relationship Management
(CRM) system or a computer soccer game.
12
Object oriented
Programming
• It places the data and the operations performed on
these data within a single data structure.
13
Object oriented
Programming
• Object oriented programming has taken the best
ideas of structured programming and has combined
them with several powerful concepts that allow the
programmer to organize programs more effectively.
14
Object oriented
Programming
• Object-oriented programming (OOP) languages are
designed to overcome the previous problems:
1. The basic unit of OOP is a class, which
encapsulates both the static attributes
and dynamic behaviors within a "box",
and specifies the public interface for
using these boxes. Since the class is
well-encapsulated (compared with the
function), it is easier to reuse these
classes. In other words, OOP combines
the data structures and algorithms of a
software entity inside the same box.
15
Object oriented
Programming
2. OOP languages permit higher level of
abstraction for solving real-life problems. The
traditional procedural language (such as C
and Pascal) forces you to think in terms of
the structure of the computer (e.g. memory
bits and bytes, array, decision, loop) rather
than thinking in terms of the problem you
are trying to solve. The OOP languages (such
as Java, C++, C#) let you think in the problem
space, and use software objects to represent
and abstract entities of the problem space to
solve the problem.
16
Object oriented
Programming
• As an example, (computer soccer games). It is difficult to model the game in
procedural-oriented languages. But using OOP languages, you can easily model the
program accordingly to the "real things" appear in the soccer games:
19
20