Procedure Oriented Programming Emphasis on procedure in terms of underlying machine model. Ability to reuse the code Eg: C, PASCAL , C++
Procedure Oriented Programming Factorial Program in C: #include<stdio.h> int main() { int i,fact=1,number; printf("Enter a number: "); scanf("%d",&number); for(i=1;i<=number;i++){ fact=fact*i; } printf("Factorial of %d is: %d",number,fact); return 0; }
Logic Programming Emphasis on knowledge base and the problem Very much like proof of mathematical statement Solves logical problems like puzzles, series Eg: Prolog
Format : relation(entity1, entity2, ....k'th entity). Example : friends(raju, mahesh). singer(sonu). odd_number(5). These facts can be interpreted as : raju and mahesh are friends. sonu is a singer. 5 is an odd number. Logic Programming
Functional Programming Based on Mathemetical Functions and Lists Language independent Execution of series of Mathematical functions Eg: LISP , Javascript
Example – LISP: Factorial of ‘n’ Program: (defun factorial (n) (if (= n 0) 1 (* n (factorial (- n 1))) ) ) (loop for i from 0 to 16 do (format t "~D! = ~D~%" i (factorial i)) ) Functional Programming
Object Oriented Programming Emphasis on Data rather than Process. Object is the basic entity is object. Handle almost all kind of real life problems. Eg: SIMULA, SMALLTALK , C++, JAVA
Object Oriented Programming class factorial{ int f, n; public: void fact(); }; void factorial::fact() { f=1; cout<<"\nEnter a Number:"; cin>>n; for(int i=1;i<=n;i++) f=f*i; cout<<"\nFactorial of "<<n<<" is"<<f; } void main() { factorial ob; ob.fact(); getch(); }
Need for OOP To make your code: Easier to read, manage, update and implement. Performance improvement by fast execution Data Security Easy code updation Simplify
Eminent Persons Alan Kay Inventor – OOP Bjarne Stroustrup Inventor – C++ James Gosling Inventor- JAVA
POP vs OOP POP OOP Program is divided into functions. Program is divided into objects. Top-down approach. Bottom-up approach. Limited Data Security Data Security using access specifiers Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python
OOP Concepts
Summary Programming Paradigms Object Oriented Programming POP vs OOP OOP Principles