Home > DeveloperSection > Articles > Object Oriented Programming

Object Oriented Programming


OOPS PHP  OOPS 
Ratings:
0 Comment(s)
 466  View(s)
Rate this:

Object Oriented Programming


Object oriented programming uses different set of programming language as compared to older procedural programming language(like Pascal, C, etc).OOPS are based on the concept of “objects” , which contains the data, in the form of field which is also known as attribute; and code, often known as methods.


Object oriented programming allows developers to group similar tasks into classes. Object Oriented Programming is a programming style in which all variables and functions are kept in a single class.


The first step in OOP is to identify the object, once the object is identified than it is generalized as a class of object which defines the kind of data it can contain and use logic to manipulate it.

OOPs revolve around these concepts:

1) Object

2) Class

3) Polymorphism

4) Inheritance

5) Encapsulation

6) Abstraction

7) Reusability

8) Dynamic binding

9) Message passing

1) Object

Anything in this real world is an object. Look around and you will find lots of objects like mobile, car, laptop, etc. These objects have two things properties and behaviors. If you can find properties and behaviors of object then it will be very easy for you to understand object oriented programming.

Let’s take an example of car. Your car has property like color, brand, etc and behavior it can go forward and backward.

2) Class

A class is a blueprint of data. Class represents all the properties and behavior of an abject. For example, before building a house you will require a blueprint which defines the shape of the house, how rooms to be made and how they should be connected all these things are planned out, even though the house doesn’t exist. In programming we call blueprint as class.

  note.jpgRules for naming classes:

·         A class name must begin with a letter & can be followed by a sequence of letters (A-Z), underscore (_), and digits (0-9).

·         Special Characters such as? ( ) @ # $ % $ cannot be used in the class name.

·         A class name should not be same as reserved keywords.

3) Polymorphism

 Polymorphism is one of the most important concepts in OOP. The word polymorphism derived from two Latin words poly (means many)and morphos (means forms). When one task is performed in different ways or reuse the single code multiple times is known as polymorphism. Polymorphism is termed as the third pillar of OOP without it programming is incomplete.

For example: integers and floats are implicitly polymorphism as using them you can perform add, subtract, multiply, etc.

Polymorphism are of two types runtime polymorphism (also known as overriding) and compile time polymorphism (also known as overloading).

4) Inheritance

Creating a new class from existing class is called inheritance. When some class requires a same properties and methods of an existing class, then instead of recreating those members you can inherit the existing class, this is known as inheritance. So, inheritance is the process in which object of one class inherits the members of another class.

During inheritance the class which is inherited is called a parent class or a base class and the new class is known as child class or derived class. Concept of the inheritance is similar to inheritance in real world. For example: child inherits the characteristics of their parent.

5) Encapsulation

Encapsulation is a process of binding the data members (properties and variables) and member functions (methods) into a single unit. It keeps the data and the code safe from external interference. With the help of encapsulation the classes can be separated and prevented coupling with each other.

Using encapsulation, a class can change the internal implementation without changing the functionality of the program.

For example: Power steering of a car is a complex system and contains lots of components internally. But for the external world the complexity is hidden. Moreover, steering unit is independent and does not affect the functionality of any other mechanism.

6) Abstraction

An abstraction is a process where relevant data is shown and complexity is hidden in order to reduce complexity and increase efficiency.

  “Abstraction means working with something we know how to use without knowing how it works internally.”

For example: When you switch on the television set you know how to use it but you don’t need to know how it works internally.

note.jpg Abstraction and encapsulation are interrelated: Abstraction focuses on the behavior of an object whereas encapsulation focuses on the implementation.

7) Reusability

The principal goal of object oriented programming is to make the code reuse whenever possible. Reusability is important because of the two reasons: First, it enables developers to be more efficient because using the same code can be developed once and used wherever possible. Second, reliability can be achieved by reusability. The development of new code involves additional costs, time and money for testing, verification and validation.

8) Dynamic binding

Dynamic binding is also known as late binding or dispatch binding or runtime binding. In late binding the method, compiler does not know about the kind of object or the type of object or what properties or method are contained in object. The properties and variables are identified and checked only at the run time.

9) Message passing

Message passing is a type of communication in which one object sends data to another object to invoke methods .Message passing can be synchronous or asynchronous. In synchronous message passing sender and receiver waits for each other while transferring data or information. In asynchronous message passing sender and receiver do not wait for the each other while transferring the information.

Object Oriented Programming in PHP

Object Oriented Programming is a style that enables developers to group similar task into a single class. With PHP, OOP started to become more feasible. PHP is a server side scripting language and a powerful tool for making dynamic web pages. It is a language used for building complex application .By utilizing the full power of object oriented programming language you can reduce the time that you are spending in coding and use it to build better websites.

 

These below following topics used in php programming 


Topics

Description

Class and Object

In this part you will learn about the basics of class and object. How to implement the class and object in PHP

Magic function in PHP

Magic methods are starts with prefix_ like _get, _tostring, etc. You will learn how to use these methods.

Visibility in PHP

You will learn about the access modifier of OOP in PHP (public, protected and private)

Static method in PHP

In this section, you will learn how to use static method and properties.

Inheritance

How to inherit the properties and methods of parent class.

Abstract Class and Interface

In this part, it is explained how to use abstract class and when to use. Also the basic concept of interface how behavior of one class passes to another class.

Overloading and Overriding

This section covers how to implement overloading and overriding.

Object Cloning in PHP

In this part you will learn how to clone the class. How to implement the object of clone class.

Method Chaining

In this part we will explore the characteristics of method chaining

Type Hinting in PHP

In this section you will learn how to implement type hinting.


Don't want to miss updates? Please click the below button!

Follow MindStick