What is Object Oriented programming or OOP?

Object Oriented programming (oop) is a programming method whose main structure or block is composed of objects or objects. In this article, I am going to familiarize you with the concept of object oriented programming in programming. Before creating object-oriented programming, programs and software were mostly coded procedurally. In programming, the whole program was divided into a number of functions. In other words, programs written by this method are composed of variables that store data and functions that perform operations on these data.
As the software expanded, programmers had to repeat the code permanently. To do this, functions in different sections were called in an unethical and nested way, and the program was converted to a Spaghetti code. Spaghetti code is a code in which different parts of the code and functions are interdependent but unordered, and this causes the change in each function to lead to the disorganization of many functions.
Object Oriented programming

Object Oriented programming formation process

After creating Object Oriented programming, all functions along with the variables associated with them were collected in a set called Class. All objects are also produced from these classes. As a result, these objects take over all methods and attributes. The opposite is true, and classes can inherit their functions or characteristics. This is called inheritance or inheritance in programming. To better understand this, we give an example. Suppose you have a Sumsung S9 mobile phone. The Sumsung S9 phone class inherits from the handset class. This class (the same class as the handset) has the features that we refer to below.
  • Display Resolution
  • Camera Resolution
  • Memory
  • And….

Object Oriented programming It also includes the following functions:

  • Photography capability
  • Receive and send SMS
  • Ability to charge and…
The code shown below shows the phone’s empty class:
class Mobile {
    protected $color;
    protected $resolution;
    protected $cameraResolution;
    protected $memorySize;

public function charge() {}

public function takePhoto() {}

public function getSMS() {}
Now we add the keyword Extends. In this case, the phone’s class methods and features are inherited by the Sumsung S9 class:
class SumsungS9 extends Mobile {
    private $gadgets = array();

The Sumsung S9 class inherits all of these functions and features with an inheritance from the phone class. In addition, it also has Gadget features. The Sumsung S9 phone you have is an example of the Sumsung S9 phone class and is produced by building an object or object from the Sumsung S9 phone class.
$mysSumsungS9 = new SumsungS9();
Object Oriented programming

Ranges territory in oop

In the codes mentioned in the example above, you can see that we used private and public protected words to define methods and features. In fact, by using these words, for class methods and features, we define a specific territory in Object Oriented programming. These keywords are called Access Modifier. In summary, we can say that:
  • Public: Includes variables and methods that can be accessed outside of class.
  • Protected: Includes variables and methods that can only be accessed from classes inherited from the current class.
  • private: Includes variables and methods that cannot be accessed from outside the classroom.

oop in the real world

You might think that in the real world Object Oriented programming doesn’t happen as we did in this article, and you don’t need to make object from the class of a phone. We have to say that in the real world, the whole existence of a software or program is in the form of objects (even every single record of database tables). These categories can refer to the Message class, which inherits different types of Message classes such as Broadcast Message or Private Message.
Object Oriented programming

And in the end,

Mirbazorgi’s website aims to help you learn and fix your problems by providing articles and practical experiences. Email me if you have any questions.