0% found this document useful (0 votes)
5 views

04 Lecture Four

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

04 Lecture Four

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

By

Dr. Ahmed Taha


Lecturer, Computer Science Department,
Faculty of Computers & Artificial Intelligence,
Benha University Lecture 4
1
Lecture Four

Structured Programming vs Object


Oriented Programming
2
3
4
Programming
Paradigm
• A programming paradigm is a fundamental style of building the
structure and elements of a program.

• A programming paradigm is a style, or “way,” of programming

• Programming paradigms are a way to classify programming


languages based on their features.

• Languages can be classified into multiple paradigms.

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.

• Structured programming is a technique that


emphasizes breaking a program into logical sections
called blocks.
9
Structured
Programming
• Structured programming contains the following control structures that
control the program execution:
1. Selection
2. Iteration
3. Top down design (dividing the program into modules & functions)

• With structured programming, it was possible to write complex programs


easily.

• However, once a project reaches a certain size, its complexity exceeds


what a programmer can manage.

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.

• This concept simulates the real world in which all


objects have both attributes and activities
associated wit them.

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:

1. Player: attributes include name,


number, location in the field, and
etc; operations include run, jump,
kick-the-ball, and etc.
2. Ball:
3. Reference:
4. Field:
5. Audience:
6. Weather: 17
Benefits of OOP
1. Ease in software design as you could think in the
problem space rather than the machine's bits and bytes.
You are dealing with high-level concepts and
abstractions. Ease in design leads to more productive
software development.

2. Ease in software maintenance: object-oriented software


are easier to understand, therefore easier to test,
debug, and maintain.
18
Benefits of OOP

3. Reusable software: you don't need to keep re-


inventing the wheels and re-write the same
functions for different situations. The fastest and
safest way of developing a new application is to
reuse existing codes - fully tested and proven codes.

19
20

You might also like