Object Oriented Programming

Kemal Talha KOÇ
4 min readJan 2, 2022

--

I want to talk about object oriented programming. Procedural programming was used before object oriented programming was invented. However, New paradigms are those that create to solve the problems of the previous ones. For this reason, I would like to talk about procedural programming paradigm and its disadvantages before object oriented programming.

What is procedural programming?

As seen in the picture above, it is to design the flow of the program with a single main function. In this main function, other needed functions are called and the communication between functions is done with global variables. Disadvantages of this paradigm:

  • Very long and unreadable codes and functions
  • Hard to maintain codes
  • Difficult to write codes
  • Difficulties in associating with real problems
  • Security vulnerabilities due to global data

Due to these disadvantages, the object oriented programming paradigm was produced by Alan Kay in the early 1960s. Object-oriented programming is a programming paradigm that proposes solving real-life problems by modeling them with classes and objects.

In object-oriented programming, the codes in the stream are divided into classes. The responsibility of the main function in the procedural paradigm can be given on different classes in the object oriented paradigm. Classes are the template for repetitive code. Objects are structures that derive from these classes and have properties and capabilities. As seen in the example above, human is a class. This class can be used when a new human object is needed. This objects height, weight and hobbies features are set or get via attributes. This human object can run, kick, jump via methods. Attributes are human objects’ features and methods are their capabilities. Advantages of object oriented programmings are:

  • Readable codes and functions
  • Easy to maintain codes
  • Reusability thanks to inheritance
  • Flexibility thanks to polymorfizm
  • Understandable patterns and codes

There are four fundamental features in object oriented programming:

Encapsulation: Wrapping of data in a class with methods or protecting it from being modified in other classes.

In this example, Name property is private. EmloyeeName property has ‘get and set method’. Other classes can only call these methods and Name property is protected from misuse. In general, data in a class should be able to be changed with methods.

Abstraction: Hiding of complex and unnecessary details behind simple methods.

In the example above, there are many complex processes involved in driving a car. But the driver should only see the processes involved in driving the car. Other complex processes should be hidden.

Polymorphizm: Different types of objects derived from the same class exhibit different behavior for the same method.

In the example above, the Circle, rectangle, and square classes are derived from the same shape class. Each exhibits different behavior for the draw method of the shape class. Polymorphism is frequently used in Gang of Four’s design patterns.

At the same time, overloading is a type of polymorphism. In other words, methods that behave differently with different parameters in the same class can be shown as an example of polymorphism.

Inheritance: the transfer of all properties and methods of the superclass to the subclass.

In this example above, Mobile Phones and Cord Phones have all Phones’ and Electronics Items’ properties and functions. Earplugs and Stereos have all Sound Systems’ and Electronics Items’ properties and functions. Inheritance enables code reuse.

In conclusion, object oriented paradigm has a lot of advantages. Much cleaner and more understandable code can be written by understanding and using the principles of object-oriented programming.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kemal Talha KOÇ
Kemal Talha KOÇ

Written by Kemal Talha KOÇ

I am a software engineer. I am trying to develop easy to maintain, clean, understandable, sustainable codes. I like software and i like to write about it.

No responses yet

Write a response