Object Oriented Programming | Set 1 (Introduction)

Maaz_Bin_Asad
3 min readJun 20, 2020

Object oriented programming or so called oops, is a paradigm of programming languages that deals with objects being created under particular class consisting of some functions or methods that can be performed for every object passed into class.

I know this was a bit technical explanation though of this concept. Let’s dive into what actually they mean, when they say “oops”. Let’s say, you got a pressure gauge to measure tyre pressure of an Audi car. You note down the pressure, you bring another pressure gauge, you measure the pressure of Lamborghini this time and bring a new gauge for next cars and so forth. Yes ! It sounds stupid to me also. Even if it’s feasible for some Bill Gates kind of person, still; managing your work is more important than completing it with makeshift. So, it’s pretty obvious that a person should use same pressure gauge for different cars he operate on. Okay ! Enough of practical example. Let’s relate it with programmable oops now. Your car is the class, object is your Audi, Lamborghini, etc. and that pressure gauge is your method or function of that class. Now, for running a particular method on any object you just need to call that particular method for that object. Whenever you are in need to run a method on particular object, you can just enclose it inside a class an enjoy running it on million different objects belonging to same class. The work just got easy right !

The sample code snippets of C++ and python respectively, for above concepts being

Abstraction

As discussed earlier, you needed a pressure gauge to measure the pressure of respective objects right ? Moreover, you were able to measure the pressure without knowledge of working principle behind this gauge. The laws used for measuring the pressure were hidden from you and still, the instrument worked pretty fine. This hiding of working algorithms behind some method and allowing you to only access that particular method is what we call abstraction. Taking an example from python, you must have probably used a method in Python called ‘.sort()’. This method sorts the given list for you. However, you were using this method without even knowing what sorting algorithm could have been doing this task for you. This is abstraction for you !

Encapsulation

The principle used inside pressure gauge is analogous to the algorithm written in .sort() method discussed earlier.
"The Bourdon pressure gauge uses the principle that a flattened tube tends to straighten or regain its circular form in cross-section when pressurized. ... Differential pressure can be measured by gauges containing two different Bourdon tubes, with connecting linkages."
The above definition is what I found from Google. This working principal written in the method that we access from the object is enclosed in a class. By the way, the algorithm used in .sort() method in Python is TimSort and many of you use this method without needing the knowledge of TimSort algorithm. This is encapsulation for you !

Below is the pictorial explaination for abstraction and encapsulation for ya !

You use your touch screen mobile phones without needing the knowledge of touch sensors and capacitors that actually do this task for you.

Conclusion

The object oriented programming does make operations easier and understandable and for obvious reasons, find it’s applications in wide variety of development. Besides, it helps open source developers as well, because of the readability of the code and less effort to alter and create big things.

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

Maaz_Bin_Asad
Maaz_Bin_Asad

Written by Maaz_Bin_Asad

I write blogs, poems and codes | I find myself in Machine Learning | Electronics Engineering (ZHCET)

No responses yet

Write a response