Are Object oriented Programming Concepts used in WordPress?
What is object oriented programming
Object oriented programming, or OOP in short, is a type of programming language that has its unique programming techniques. OOP as the name suggests, is based on ‘objects’. Here an object is an instance of a class that is used as a building block of the program. Non-OOP languages are more of an ordered list of commands that are to be executed. OOP programs on the other hand gives the appearance of an interconnected web of interactive objects sharing and receiving information from each other.
The main difference between object oriented languages, such as C++ and Java, and non object oriented languages (or procedural languages), such as C and C#, is the distinction in use of functions and classes. While procedural languages are driven by functions, OOP languages are driven by Classes, which are a combined and compartmentalized form of both functions (called methods in OOP jargon) and variables.
A brief history of OOPS in web development
Since the launch of PHP 5.0 in 2004, web development started seeing a direct involvement of object oriented architectures and OOPS concepts. PHP 5.0 gave improved support for object oriented programming and through its PHP Data Objects (PDO) extension programmers could now directly use OOP concepts such as classes, inheritance, and overloading in web development.
Object-oriented programming in WordPress
WordPress relies heavily on object oriented techniques. If you look into the WordPress directory, in the ‘wp-include’ folder you will find at least 28 PHP files named ‘Class-something’. Yes, you guessed it right; these are the files that fully employ object oriented techniques and these files are an integral part of WordPress software. They contain all the main classes that are the backbone for creating user interfaces and defining the functionality of a software.
In addition plugins and widgets, that are another important part of every WordPress site, can also be created by using object oriented techniques (See this tutorial https://code.tutsplus.com/tutorials/two-ways-to-develop-wordpress-plugins-object-oriented-programming–wp-27716)
Why use Object-Oriented Programming
So now the question arises, why use object oriented programming? The answer is simple; it makes a program neat, clean, and properly structured. Through object-oriented programming techniques, programs become-:
- Easy to code and easy to decipher,
- Easy to debug,
- Highly organized,
- Easy to adapt to different functionalities,
- And easy to use.
In addition to these advantages another noteworthy thing is the usage of a combination of OOPS and PHP. You can use a particular class outside of the plugin or widget. Because of this it is easy to design and develop themes that specifically uses a plugin or a widget to improve the theme’s functionality. Similarly, you can create interconnected plugins, widget, themes, etc. This customizability is the main feature that attracts programmers and users alike to PHP programming.
Saying that OOP in not used in web development is kind of unfair. OOPS may not have heavy influence on Client side coding but it is used heavily in Server side coding through JAVA, ASP.NET, and PHP. Also use of object oriented programming may improve usability and coding, but it increases the code size and thus exerts a bit of load on the processor.
It is insignificant if you are using a decent processor, but in cases where there are limited computational resources, OOP is at a disadvantage.