[oop - lec 03] programming paradigms

16
Programming Paradigms Muhammad Hammad Waseem [email protected]

Upload: muhammad-hammad-waseem

Post on 06-Apr-2017

152 views

Category:

Education


7 download

TRANSCRIPT

Page 1: [OOP - Lec 03] Programming Paradigms

Programming ParadigmsMuhammad Hammad [email protected]

Page 2: [OOP - Lec 03] Programming Paradigms

Programming Techniques• The evolution of programming techniques is • to make programming languages more expressive • to develop complex systems more easily

• There are different programming paradigms• Unstructured Programming • Procedural Programming • Modular & Structural Programming• Object-Oriented Programming

Page 3: [OOP - Lec 03] Programming Paradigms

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.

Main Program

Data

Page 4: [OOP - Lec 03] Programming Paradigms

Drawbacks of Unstructured Programming• This programming technique can only be used in a very small

program.• For example, if the same statement sequence is needed at different

locations within the program, the sequence must be copied. • If an error needed to be modified, every copy needs to be modified.• This has lead to the idea to extract these sequences(procedure),

name them and offering a technique to call and return from these procedures.

Page 5: [OOP - Lec 03] Programming Paradigms

Procedural Programming• With procedural programming, you are able to combine sequences of

calling 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.Main Program

Procedure

Page 6: [OOP - Lec 03] Programming Paradigms

Procedures• With parameters and sub-procedures (procedures of procedures) ,

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.

Page 7: [OOP - Lec 03] Programming Paradigms

Procedure Program View

Main Program

Data

Procedure 1 Procedure 2 Procedure 3

Page 8: [OOP - Lec 03] Programming Paradigms

Modular Programming • Modular programming is subdividing your program into separate

subprograms such as functions and subroutines. • 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 divided into several smaller parts which interact through procedure calls and which form the whole program.

Page 9: [OOP - Lec 03] Programming Paradigms

Modular Programming Program View

Main Program(Also a module)

Data

Data1

Module 2 + Data Data2

Module1+Data Data1

Procedure1 Procedure2 Procedure3

The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters.

Page 10: [OOP - Lec 03] Programming Paradigms

Modular Programming• 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. • Each module has its own special functionalities that supports the

implementation of the whole program.

Page 11: [OOP - Lec 03] Programming Paradigms

Structural Programming• Also structured programming• A subset of procedural programming that enforces a logical structure

on the program being written to make it more efficient and easier to understand and modify. • Certain languages such as Ada, Pascal, and dBASE are designed with

features that encourage or enforce a logical program.

Page 12: [OOP - Lec 03] Programming Paradigms

Problems with Structured Programming• Many Functions access the same data, change in data may require

rewriting of all functions. It makes program difficult to modify.• It makes a program structure difficult to conceptualize.• Arrangement of separate data and functions does a poor job of

modeling things in real world.

Page 13: [OOP - Lec 03] Programming Paradigms

Object-Oriented Programming• OOP is a technique in which programs are written on the basis of objects.

An object is collection of data and functions.• The fundamental idea behind object oriented programming is to combine

both data and functions into a single unit. Such a unit is called object.• Object is derived from abstract data type.• Object-oriented programming has a web of interacting objects, each

house-keeping its own state.• Objects of a program interact by sending messages to each other.• OOP is based on real world modeling

Page 14: [OOP - Lec 03] Programming Paradigms

Object-Oriented Programming Program View

Object1

Data1+Procedures1

Data Data1 Object3

Data3 + Procedures3

Object2

Data 2 + Procedures 2

Object4

Data4 + Procedures4

Page 15: [OOP - Lec 03] Programming Paradigms

Object-Oriented Programming• In object-oriented programming , instead of calling a procedure which

we must provide with the correct handle, we would directly send a message to the object in questions. • Roughly speaking,• Each object is responsible to initialize and destroy itself correctly.• Consequently, there is no longer the need to explicitly call a creation

or termination procedure.• Each object implements its own module.

Page 16: [OOP - Lec 03] Programming Paradigms

Object Oriented Languages• C++• JAVA• C# (C Sharp)• Many other