POP vs OOP Introduction

874 views 37 slides Sep 01, 2021
Slide 1
Slide 1 of 37
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37

About This Presentation

Detail Explanation of POP vs OOP for beginner


Slide Content

Procedure-Oriented Programming vs Object Oriented Programming

Programming Language : Definition A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks.

Programming Languages Programmer use Programming languages to develop the software. The three major families of languages are: Machine languages Assembly languages High-Level languages

Machine Languages Comprised of 1s and 0s The “native” language of a computer Difficult to program – one misplaced 1 or 0 will cause the program to fail. Example of code: 1110100010101 111010101110

Assembly Languages Assembly languages are a step towards easier programming. Assembly languages are comprised of a set of elemental commands. (MNEMONICS) Assembly language code needs to be translated to machine language before the computer processes it. Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

High-Level Languages High-level languages represent a giant leap towards easier programming. The syntax of HL languages is similar to English . Historically, we divide HL languages into two groups: Procedural Oriented Programming Object-Oriented Programming (OOP)

Procedure-Oriented Programming Large programs are divided into Smaller Programs know as function. Most of the functions share global data. Data move openly around the system from function to function. Top-down approach in program design.

Object -Oriented Programming Striking feature Programs are divided into what are known as objects. Data is hidden and cannot be accessed by external functions. Program can be easily extend whenever necessary. Bottom-up approach in program design.

Structured programming enable programmers to write moderately complex programs fairly easily. However as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain and reusable programs.

Object-Oriented Programming (OOP) is an appraoch to program organization and development that attempts to elimate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts.

Procedure-Oriented Programming Conventional programming using high level language such as COBOL, FORTRAN and C is commonly known as Procedure-oriented programming. In the Procedure-oriented approach the problem is viewed as a sequence of things to be done . The primary focus is on functions.

Structure of Procedure-oriented Main Program Function 1 Function 2 Function 3 Function 5 Function 4

Procedure-Oriented Programming Procudure-oriented programming basically consists of writing a list of instructions for the computer to follow and organizing these instructions into groups known as functions.

Structure of Procedure-oriented Global data Function 2 Global data Function 3 Function 1 Local data Local data Local data

Procedure-Oriented Programming What happens to data? How are they affected by the functions that work on them? In multi-function program many important data items are placed as global so that they may be accessed by all the functions.Each function may have its own local data. In large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure we also need to revise all function that access it.

Object-Oriented Programming OOP treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it, and protects it from accidental modification from outside functions. OOP allows decomposition of a problem into a number of entites called objects.

Organization of data & function OOP Data Functions Data Functions Data Functions Object C Object A Object B

Basic concepts of OOP Objects Class Data Abstration Encapsulation Inheritance Polyomorphism Dynamic binding Message Passing The three pillars of object-oriented development: Encapsulation, Inheritance, and Polymorphism.

Object Object is a real world entity, for example, chair, car, pen, mobile, laptop etc. In other words, object is an entity that has state and behavior. Here, state means data and behavior means functionality. Object is a runtime entity, it is created at runtime. Object is an instance of a class. All the members of the class can be accessed through object. Let's see an example to create object of student class using s1 as the reference variable. Student s1;  //creating an object of Student     

Object Example

Object and Class

Class Class is a model for creating objects. A class is the building block, that leads to Object-Oriented programming. A class is thus a collection of objects of similar types. It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A class is like a blueprint for an object or blueprint for creating objects (a particular data structure), providing initial values for state (member variables or attributes), and implementations of behavior (member functions or methods).

Class Class is a template from which objects are created. It can have fields, methods. The user-defined objects are created using the class  keyword. The class is a blueprint that defines a nature of a future object. An  instance  is a specific object created from a particular class. Classes are used to create and manage new objects and support  inheritance —a key ingredient in object-oriented programming and a mechanism of reusing code

Cl asse s O n ce a c la ss h a s b e e n de f i n e d w e c a n cr e a te a n y number of objects belonging to that class.

Cl asse s Fruit is a class defined as a Class. fruit f1; Here fruit is Class. And f1 is an object of fruit Class.

Encapsulation The wrapping up of data and functions into a single unit is known as Encapsulation The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. This insulation of the data from direct access by the called data hiding or information p r og r a m is hiding.

Data Abstraction Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost, and functions to operate on these functions. Since the c l a s s e s u s e t h e c on c ep t of da ta abstraction, t h e y a r e k n o w n a s Ab s t r a c t D a ta Types.

Inheritance I nhe r i t an c e is t h e process by which objects o f one c la ss a c q ui r e t h e properties of objects of ano t he r class. The principle behind this sort of division is that each derived class shares common characteristics with the class from which it is derived. (Base class) In OOP the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it.

Inheritance The real power of inheritance mechanism is that it allows the programmer to reuse a class that is almost but not exactly, what he wants, and to tailor the class in such a way that it does not introduce any undesirable side-effects into the rest of the classes. B i r d Flying Bird No flying Bird

Polymorphism Polymorphism means the ability to take more than one form. That is an operation may exhibit different behaviours in different instances. The behaviour depends upon the types of data used in the operation. Example: Operation of addition. For two numbers the operation will generate a sum. If the operands are strings, then the operation would produce a third string by concatenation.

Polymorphism The process of making an operator to exhibit different be h a v i o u rs i n d i f f e r en t i n st an c e s i s k no w n as operator overloading. Using a single function name to perform different types of ta s ks is known as function overloading.

Dynamic Binding Binding refers to the linking of a pr o cedure call to the code to be executed in response to the call. "Binding" means associating a function for a particular function call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time . I t i s as s o c i a t e d w i t h po l y m o r ph i s m and inheritance.

Message Communication An object-or iented program consi s ts of a set of objects that communicate with each other. Object communicate with one another by sending and receiving information much the same way as people pass message to one another. Message passing involves specifying the name of the object, the name of the funciton (message) and the information to be sent. emp.salary(emp_name); ob j ect m e ss ag e information

Benefits of OOP Through inheritance we can elimate the redundant code and extend the use of existing code Data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program It is possible to have mulitple instances of an objects to co-exist without any interference. Easy to partition the work in a project based on objects

Benefits of OOP Da t a - c e n t r e d de s i g n a p p r o a ch en a b l e s u s t o c a p t u r e more details of a model in implementable form Object-oriented systems can be easily upgraded from small to large systems . Easy to read the code and debug Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler. Software complexity can be easily managed.