Wednesday, August 18, 2021

Day1 - Object oriented programming in Python

 8/18/2021
Day1 - Object oriented programming in Python
When you are learning something, learn like a child.
When you are working, work like a professional.
Programming language approach
1. Procedural
2. Object oriented
Procedural oriented programming approach
- In procedural oriented programming approach, program (solution) is a collection of function, or method or, procedure. (Block which represent some logic)
Structure of procedural oriented programming
m1() # Method definition
  {
    logic # some logic
  }
m2() # define m2 method
  {
    logic     # some logic
  }
main() # Main method
 {
   m1
   m2
  }
In this program we have three methods: m1, m2 and main methods. 
We have 50 sits and one driver sit. 
driver is a main method. main method controls the program the way driver controls the bus.
In above program
- First program execution starts from main method
- Second, it reads the m1 method and control goes to look for m1 method and when it finds, it executes it
- 3rd, it reads m2 and control goes to look for m2 method and reads the logic and executes the block of code.
A programming language which follows the above programming approach is a procedural oriented programming language.
Due to some limitation of this approach, industry experts are intruducing a new programming approach which is called object oriented programming approach.
Object Oriented programming approach (OOP)
-> In OOP approach, the program is a collection of classes. A programming language that follows above programming approach is an object oriented programming language.
Structure of OOP approach
class c1 # definition of class
{
  m1() # definition of mdule
     {
        logic
     }
   m2() # definition
     {
         logic
     }
}
class c2
{
  main() # definition of main method. programming execution control by main method
  {
    c1.m1 # calling
    c1.m2
  }
}

Program execution starts from main method. After that control checks c1.m1 and start look for c1 and m1 and executes when it finds it
after that control goes to c1.m2. It start looking for c1 cladd and go to m2. once it reads, it executes. 
when control reaches the closing braces, program terminates. This kind of programming approach is called OOP. languages
Some of them are c++, JAVA, C#.net
What about python?
- python is procedural as well as oop.
function, method -> procedural
class - oop
m1() # function, method
{
}
m2()
{
}
class c1 # class
{
 m3()
  {
  }
}

OOPS methods
Every OOP language follows 4 principles
1. Encapsulation
2. Abstraction
3. Polymorphism
4. Inheratence
To achieve all 4 princliples, every object oriented programming language has to follow the 2 object orientted concepts below.
1. class
2. object
What is object?

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...