Monday, January 2, 2023

Object Oriented Programming (OOP)

OOP Programming SeekerzZ
Object Oriented Programming (OOP)
Object oriented programming OOP is a programming technique which is used by many programming languages and in this you have to use classes which are a user define data type and you create functions and attributes according to your use and then to use them you have to create an object or instance of that class so that you are able to access the attribute and operation of that class.
Advantages:
The object oriented programming have a main advantage of code reusability that you have to create a class for one time and then just have to create its instance where ever you want to use it.
The main concepts of object oriented programming are given below:
  • ·         Inheritance
  • ·         Encapsulation
  • ·         Overloading
  • ·         Polymorphism
  • ·         Abstraction

As we already discuss all of these topics in over previous posts but for now take a little review of all of them. Inheritance as the name suggests inheriting something from other. In this we have a supper and sub class hierarchy and sup classes are inherited form super classes and was able to use the functionality and attributes of super class. Many type of inheritance is there:
  • ·         Single level inheritance
  • ·         Multi-level inheritance
  • ·         Multiple inheritances
  • ·         Hybrid inheritance

For more there are other two very important concepts in inheritance which is following:
  • ·         Generalization
  • ·         Specialization

Encapsulation mean data hiding in classes we have to define the scope of every object and function by default they are all private. We have normally three scope resolution operator.
  • ·         Public
  • ·         Private
  • ·         Protected
  • ·         Sealed
  • ·         Sealed internal

Overloading provides us the y to define same thing with different meaning there are two type of overloading:
·         Function overloading
·         Operator overloading
In function overloading we have many functions with same name but different data type and in operator overloading we re-write the functionality of different operators like =, <, >, ||, $$ etc.

Polymorphism means many ways. In this we have many ways to class a function it cover the topic of function overriding.
The polymorphic classes contain two types of functions
  • ·         Virtual function
  • ·         Override functions


OOP languages:
There are many object oriented programming languages in which some are pure object oriented and some have both procedural and also object oriented way.
Java and C# are pure object oriented languages
C++, PHP, JavaScript are not pure object oriented but have functionality of it.

Constructor:
The constructor is default functionality in all object oriented languages which come with the classes whenever we create object of the class the default constructor call and execute its code first without calling it.
In C++, Java and C# constructor have the same name as class name and have no data type but in PHP we have to define constructor like this:

Function __construct( ) {  }




Example class in PHP:
<?php
class person{
            function __construct(){
                        echo "<h1>Person Information</h1>";
            }
            private function get_ID($id){
                        echo "<h3>Person ID No is :- ".$id.'</h3>';
            }          
            private function get_name($name){
                        echo "<h3>Person name is :- ".$name.'</h3>';
            }          
            private function get_mob($mob){//have private scope
                        echo "<h3>Person Mobile No is :- ".$mob.'</h3>';
            }          
            public function calle($id,$name,$mob){
                        $this->get_ID($id);
                        $this->get_name($name);
                        $this->get_mob($mob);
            }
}
                        $obj = new person();//object creation
                        $obj->calle(101,'Usman','0307-5230948');//function calling

?>

Share this

0 Comment to "Object Oriented Programming (OOP)"