What is Object Oriented programming or OOP?

Object-oriented programming is one of the programming methods whose main structure is made up of objects. I, Arsalan Mirbozorgi, try to introduce you to the concept of object-oriented programming in this article. In the distant past, before the design of this type of programming, most software was coded as Procedural. In this type of programming, the whole program was divided into a number of different functions. In fact, programs in this programming method consisted of variables that stored information, as well as functions that performed various operations on these variables.

With the spread of programming and the pervasiveness of this science, programmers had to replicate code permanently. To do this, in some cases, the functions could be called randomly and nested and turned into a program with spaghetti code. Spaghetti code is code in which all the parts are in a disordered and dependent manner, and this is why every small change in one function causes a lot of confusion in other functions as well.

Object Oriented programming

Object Oriented programming formation process

The process of forming object-oriented programming

After this programming method was developed, all the functions and variables that existed in procedural programming were grouped into various sets called classes. All objects in these programs are also generated from these classes. Because these generated objects are class dependent, they get all the methods and attributes of the class. Note that the opposite is also true, and classes have the ability to own all the properties of the objects produced. This type of programming is called inheritance programming. In order to better understand this issue, it is better to give you an example. Suppose you do not have a Samsung S9 mobile phone. The Samsung S9 phone class does not inherit from the phone class. This class actually has features that we will mention to you below:

  • Screen resolution
  • Camera resolution
  • Memory
  • And…

Your phone class also includes the following functions:

  • Photography capability
  • Charging capability
  • Ability to receive and send SMS
  • And …

The empty class of your phone is displayed with the following code:

class Mobile {
    protected $color;
    protected $resolution;
    protected $cameraResolution;
    protected $memorySize;

public function charge() {}

public function takePhoto() {}

public function getSMS() {}

Now if you add the Excel keyword you can inherit the phone class methods and its features by the Samsung S9 class:

class SumsungS9 extends Mobile {
    private $gadgets = array();

The Samsung S9 class inherits all the features from your phone class. In addition, this theme has the features of a gadget. The Samsung S9 you are holding is an example of a class of the Samsung S9 and is produced by making an object of the class of this phone.

$mysSumsungS9 = new SumsungS9();
Object Oriented programming

Ranges territory in oop

In the example above, you saw that the words Privacy and Public Protect were used to define the properties. In fact, using these words, we define a specific domain in object-oriented programming language. These keywords are known as access modifiers, which can be summarized for you:

  • Public includes variables and methods that you can access outside of the classroom.
  • The protocol contains variables and methods that you can access within their class. Of course, these variables must have been inherited from the current class.
  • Privacy also includes variables and methods that you cannot access from outside your classroom.

oop in the real world

You might think that in the real world, object-oriented programming does not look like the one we gave you, and you do not need to create an object from the phone class. We have to tell you that in the real world, software is an object.  Even the individual records in a piece of software are actually objects. Using these, we can give you an example of a message class to learn more about different types of classes like Broadcast Message or Private.

Object Oriented programming

And in the end,

MirBozorgi website tries to provide you with articles and practical experiences to help you learn more and fix your problems. Email me if you have any questions.

Leave A Comment

98 − = 95

Please Send Email

Your message sent successfully
There has been an error