What is OOP (Object Oriented Programming)?

Rafael Mammadov
5 min readJan 3, 2024

In this article, I will try to explain the logic of object-oriented programming (OOP) with examples from daily life and illustrate where it is used. For a better understanding of object-oriented programming, it will be useful to explain terms such as program, programming, and software.

A program, in daily life, is software written to solve a problem using a computer, simplifying routine tasks. In other words, it is a sequence of instructions intended to perform a function on the computer. To write a program, an individual needs to have general programming skills and knowledge of a programming language.

A programming language is a formal set of instructions that ensures step-by-step writing of a solution to a problem for the computer environment. It can be exemplified as the language used to transfer the problem to the computer that one wants to solve in daily life.

Software programs are designed for various missions, such as shortening user processes and increasing efficiency. Examples of this can be seen in today’s web, mobile, and desktop software programs designed to meet the needs of contemporary requirements.

Object Oriented Programming

Object-oriented programming (OOP) is the process of transforming real-world objects, such as cars, radios, and buildings, into the computer environment. For example, representing the on-off status of a lamp or the characteristics of a radio, such as its color, brand, and manufacturing year, in a computer environment.

Advantages provided by Object-Oriented Programming:

1. Representations of real objects are implemented within classes.

2. When an object is created and needs to be modified, it is not necessary to make changes throughout the entire program; modifying the created object is sufficient. Since the created objects are independent of each other, it increases the possibility of data hiding. For example, object A cannot use or access the properties of object B.

3. The creation of an object is implemented within a class, and this code can be used in other projects. For instance, if we create an object A, we can use it in many places. Through created classes, more work can be done with less code, avoiding repetition. For example, in the “human” class, we can create properties such as name, surname, age, etc., once and use them as many times as needed. Preventing code repetition increases the efficiency of the coding process.

What is a Class?

Class is a concept in which the properties and behaviors of real-world objects are transferred. The transfer of information to classes is done through methods. The methods and variables defined in a class are called the members of the class. Variables store information we will use, such as name, surname, age. Methods are subprograms that perform tasks like user registration or the sum of two numbers. A class is an abstract concept and cannot be used directly; we need to create an object first and then use it.

For example, if we have a “Person” class, the variables (properties) could be “name,” “surname,” and “age,” and the methods could include “registerUser” or “calculateSum.” These members collectively define the blueprint of the class. To use this class, we would create objects of the “Person” class, each representing a specific person with unique values for name, surname, and age.

Inheritance, encapsulation, and polymorphism are key principles of object-oriented programming that can be applied to classes to enhance code organization and reusability.

What is an Object?

Objects are components that store information and have methods to perform operations on this information. Objects can be reused in every application. When we create an object, it occupies space in memory.

Object-Oriented Programming has four main features: 1. Abstraction, 2. Encapsulation, 3. Inheritance, and 4. Polymorphism. A programming language that does not implement one of these features is not considered an Object-Oriented Programming language.

Abstraction: Simply put, abstraction “shows” only the relevant characteristics of an object and “hides” unnecessary details.

For example, when driving a car, we are only interested in actions such as starting/stopping the car, accelerating/braking — operations necessary to control the vehicle. We are not concerned with the details of how the actual starting/stopping mechanism or the acceleration/braking process works. These details do not interest us.

What we care about is the “abstract” appearance of these processes that helps us move the car and achieve our goal. This is a simple example of abstraction.

Thus, all the mechanisms and processes of the car are in place, but from the perspective of the end user, i.e., the driver, they will only be interested in the abstract appearance of these processes.

Encapsulation: Behavior and characteristics are abstracted and encapsulated within a class. With encapsulation, we determine which properties and behaviors will be visible or hidden. For example, in a human class, if we are not interested in the eating habits, we can hide (private) that information. However, details like name and surname may be of interest to us, so these details remain visible. This process is called data hiding or encapsulation. The access points of data (public, private, protected) are implemented through this process.

  • public: Properties that can be accessed by everyone.
  • private: Properties that are only used within their own class.
  • protected: Properties that can be used by subclasses inheriting from the class.

Inheritance: Inheritance is the method of creating a hierarchy by inheriting from other classes. Classes can be derived from one another, forming an inheritance hierarchy. A subclass can inherit the properties of its superclass. For example, in the classes Car and Bicycle, we can create a new class that includes common properties like the number of wheels and speed by inheriting them. If a class inherits from more than one class, it is called Multiple Inheritance.

Polymorphism: Polymorphism allows subclasses to show the properties indicated by the superclass in different ways. Subclasses are not obliged to show the same properties as the superclass indicates; this is called polymorphism. For example, considering the classes Ship and Car, they both have movement methods, but a ship moves on water, and a car moves on land. In short, polymorphism is the ability of different objects (such as a car and a ship) to respond differently to the same event (such as a movement type).

--

--