×
☰ See All Chapters

PHP OOP concepts

What is object oriented programming (OOP) language?

OOP stands for Object-Oriented Programming. Any programming language if supports Encapsulation, Abstraction, Inheritance, Polymorphism then that language is an object oriented programming language. E.g. PHP, java, C++

If programming language supports sequence structure, conditional structure and iterative structure then that programming language is a structured programming language. Procedure oriented programming (POP) and structured programming are not different, a structured programming is a part of procedure oriented programming,  while object-oriented programming is about creating objects that contain both data and functions.

Define OOP concepts?

Encapsulation: It is the Process of binding the data and functions together into a single unit. Example: Binding private variables with setter and getter functions.

Abstraction:  Showing essential properties and features of an object by hiding internal things is called as Abstraction. Abstraction is possible if and only if there is encapsulation.

Inheritance: Inheriting the properties and features of one class (super class) into another class (sub class) using IS a relationship. Example: Ferrari class inherits the features of Car class. Puppy class inherit the features of Dog class, Dog class inherit the features of Animal class.

Polymorphism: One form behaving differently in different situations is called polymorphism. Animal class behaving differently for different objects like Dog, Cat etc...

Advantages of Object-Oriented Programming

Re-usability

Classes and functions written once can be reused any number of times. We can build the programs from standard working libraries that communicate with one another, rather than having to start writing the code from scratch which leads to saving of development time and higher productivity.

Inheritance

Classes can be extended and thus without recreating a class from scratch you can inherit properties and features of any class. You can still provide additional features and modify the inherited properties and features. Suppose if you have to create Apple class, you can extend Fruit class and inherit the features of fruit. Now you can add additional features of apple to Apple class.

Modularity

OOP language allows dividing the program into any smaller units and linking them. This reduces the maintenance and up gradation will be faster. OOP programs can be easily upgraded from small to large systems. Dividing a complex problem into smaller chunks or discrete components is a good practice. OOP is specialized in this behavior, as it breaks down your software code into any desired size.

Polymorphism

Different behavior required for different scenarios, polymorphism is the concept which avoids creating different components for different scenarios. Using polymorphism you can make a single object to behave differently for different situation.

Easy troubleshooting

Fixing defects and issue takes less effort from developers. Identifying the root cause of issues is not brainstorming for the developers to look where the error is. Defects can be safely fixed without affecting the dependent features due to encapsulation support.

Productivity

Committing more work in less time is called productivity. By reusing code, by using divide and conquer strategy productivity can be improved. Work can be easily divided into smaller units and distributed to developers thus increasing the productivity.

Security

Using abstraction you can hide whatever you want and expose only essential properties and features. The principle of data hiding helps the programmer to build secure programs which cannot be invaded by the code in other parts of the program.

 


All Chapters
Author