Objects in php

February 17, 2013
Posted by admin 2:59 PM

Object is  an concrete entity constructed using the blueprint provided by  class. The class specifies the behaviors and characteristic of   object but it doesn’t specify the value of those characteristics. With a single class we can make several instances of the same class .In OOP we can make object  from class by instantiation.  For creating a new object we use the word new to instantiate a class
e.g.
<?php
class classname
{
public  variable name;                                                                                            //property of class
public  function  function_name(parameter,parameter2…parameter_n)     //method of class
   {
   }
}
$object_name=new class_name;
$object_name->function_name();                                                                           //calling the function from object
?>

In PHP we can called a method from object by using arrow(->).We can make multiple objects from same class using the keyword new.  
 

Classes in php

February 17, 2013
Posted by admin 2:49 PM

A class is a unit of code which contains variables and functions that describes the behavior and characteristic of all the members of a set. Normally it just a piece of code in our code that consist of methods and properties which describe the class behaviors and its characteristics

e.g. A class bike have its weight, color and speed, so the  weight and color are the variables  for this class and the speed is function for this class cause it depends on the fuel and other parameters  .A class bike can describe the behaviors   and characteristics of bike so  all the bike is member of this class.

In object-oriented programming the characteristics are the properties of the class and its behavior is known as the method of the class. The method is same as the functions in our normal programming works on parameters pass to them

e.g.

<?php

class classname

{

public  variable name;                                                                                           //property of class

public  function  function_name(parameter,parameter2…parametern)     //method of class

   {

   }

}

?>

 

Need Of Object-Oriented Programming

February 2, 2013
Posted by admin 2:39 PM

 

 When we are going to work with classes and objects we always think why there is need of classes and object although without classes and objects our code works well. But after some work on classes and objects we think, yeah its better to work with classes and objects .And then we can understand that Object oriented Programming is better than procedural Programming.

Object oriented programming requires a different way of thinking about how can we construct our application.

Lets take a short example:

When we are going to build a house .We distribute the works needed to make a house we can divide the works in different part and deliver to different persons like plumber for water supply, electrician for electricity etc. The electrician doesn’t need to know that the work of plumber and vice versa.

In the same way in Object Oriented Programming we can divide our applications in different modules called classes .And one class is separate from other classes .It has its own functionality and features.

So what advantages we can get from Object Oriented Programming:

1: Reusability Of Code:  In object oriented programming one class can easily copied to another application if we want to use its functionality 

       e.g.  When we work with hospital application and railway reservation application .In both application we need person class  so we have to write only one time the person class  and it can easily use in other application.

 2: Easily Discover a bug: When we work with procedural programming it take a lot of time to discover a bug and resolve it .But in object   Oriented Programming   due to modularity of classes  we can easily discover the bug and we have to change in one class only and  this change make in all the application only by changing it one class only.

3: Object- Oriented Programming enables us to easily model our applications based on the real world which help us to easily identify the requirements, what code is to be written and how different classes interact with each other which have same properties and behaviors.