What Is Object Oriented Programming?

Muzaffer Arda Uslu
3 min readNov 30, 2020

OOP, is short way for Object Oriented Programming, is an approach that emerged in the late 1960s to remove the complexity of the written code and removing the code repetition. First OOP language is Simula. We can assume, popular OOP languages are C++, C#, Java, PHP, Python and JavaScript.

This article includes Class, Object, Attribute, Methods and Encapsulation.

Look for Inheritance

Advantages of OOP:

  • It enables the written code to be reused (Code-Reusability). In this way, the cost is reduced.
  • Extensibility is provided by adding new features and methods to a written class.
  • The program becomes compatible with teamwork, thus increasing performance.
  • Since the program is divided into parts, the errors that occur are found and resolved faster.
  • Facilitates complex project production and maintenance.

OOP is based on the concept of objects. OOP is associated with concepts such as Class, Object, Inheritance, Encapsulation, Abstraction, Polymorphism etc.

Concepts of Object Oriented Programming

What are Methods and Attributes(Properties)?

Methods are actions that can be performed on the object.
Properties hold data and help identify the object.

What is Class?

Class is basically a block of code that variables and methods.

via javatutorial.net

Let’s convert the code block to a class.

Classes have constructors and destructors.

What is Constructor?

Constructor method runs automatically when an object is created.

  • Constructor method’s name has to be same with class name.
  • Constructor has no return type.
  • Constructor methods can be overload.
  • We can call our Constructor method with ‘this’ key word.

What is Overloading?

Overloading is creating methods with same name but different signatures.

Look for Overloading in C++

What is Signature?

Signature is the number, type and order of parameters a method contains.

What is Destructor?

Destructor is a member function that deletes an objects.

  • Destructor method’s name has to be same with class name and should begin with tilde sign(~).
  • Destructor has no return type.
  • Destructor methods can not be overload.

What is Encapsulation?

This feature keeps unnecessary application details from object user. In order for the user to perform their operations more easily within a class created, some operations are combined and shown as a single operation.

What are Access Modifiers?

Access Modifiers are keywords that used to determine the access levels of items in the created class or class. Methods and variables can be limited by access modifiers.

  • Public (+): It provides access to all classes in the system.
  • Private (-): Allows a property or method to be accessed only from the class in which it is defined. If the structures to be created are not specified to be “public”, they are automatically “private”.
  • Protected (#): Accessible only within the class in which it is defined and within classes derived from that class.
  • Internal (~): Access is provided from all classes in the same compiler.

We use public methods called getter and setter to access private members. Thus, the user cannot directly access the data of the class.

Only Reading, Just Writing and Writing-Reading operations are provided.

Let’s do an example.

UML of Car Class
Header File of Car Class
C++ File of Car Class
main.cpp

References:

--

--