Learn

OOP Object Oriented Programming

Object Oriented Programming
Object Oriented Programming
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

OOP abbreviation of Object Oriented Programming. As its name is also describing the definition. Let elaborate the definition little more to understand the basic concept of OOP. Object-oriented programming (OOP) is a method or style of coding which helps us in creating Objects and classes and use them anywhere in our application. Nevertheless whatever programming language you are using you can adopt the methodology of OOP. Let’s understand what is a class and what is an object.
The class is basically a code that we need to define for one time only. Then using the same class we can create multiple objects and we don’t need to write the full code again and again.

Objects are like blocks or different parts of our application that we built using our pre-defined classes.
Let me give you a real time example.

Toyota company builds about 10000 cars in a month. Same design, same specifications, same body but different colors. Now what they have done is, they defined everything in one class and then just build the cars by using that class. Class remains the same, but they build thousands of cars. Now if they want to make different colors, they just need to change the color in class simply and create the object again with the new color defined in the class. Consider this example as an application they are building 10000 cars with one class same in our web based applications sometimes we need the same concept same logic in different places. By adopting this technic, we can work more fast and professionally.

In this article, I am going to explain you the easiest and best way to work with Object Oriented Programming with real examples. As a PHP programmer, I will explain uses of OOP with PHP Code but you can use the same concept, logics in any other language you are familiar with.

How to create of class in object oriented programming.
The syntax of declaring any class is very simple. First class keyword, then class unique name and then opening and closing curly brackets.

<?PHP
class ItsMe{
// Do some magic here.
}
?>

the class is a keyword that used for declaring a class. ItsMe is the name of that class. We will put our code, logics etc between these two curly brackets.

After creating the class, next step is to create an object.
How to create an object in Object-oriented Programming
First thing we need to do before using that class. We need to initiate the class with the keyword new and store in a variable.

<?PHP
$obj = new ItsMe;
?>

In this simple code, we initiate the class named ItsMe with the keyword new and stored its output value in the $obj variable. To check the result or output of that class we use the following code.

<?PHP
var_dump($obj);
?>

Now let’s combine all these statements in one page and see the result.

<?PHP
class ItsMe{
// Do some magic here.
}
$obj = new ItsMe;
var_dump($obj);
?>

Output of the following code will be:
object(ItsMe)#1 (0) { }

So you have successfully defined your first OOP Class. In the next article, we will discuss class properties and methods.
For question, suggestions, comments, please feel to write.


  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Most Popular

To Top