Skip to main content

Happy Independence Day

 ❤  Happy Independence Day   ❤  Happy Independence Day ▂ ▄ ▅ ▇ Happy Independence Day ▇ ▅ ▄ ▂ Happy Independence Day  कुछ नशा तिरंगे की आन का है,    कुछ नशा मातृभूमि की शान का है,,    हम लहरायेंगे हर जगह ये तिरंगा,    नशा ये हिन्दुस्तान का सम्मान का है।    ये बात हवाओं को भी बताये रखना,    रौशनी होगी चिरागों को भी जलाये रखना,,    लहू देकर जिसकी हिफाजत की हमने,    ऐसे तिरंगे को सदा दिल में बसाये रखना।   Share on Whatsapp

Object Oriented Programming (OOP) - Darksitecoder

Object Oriented Programming
(OOP)

object-oriented-programming
object-oriented-programming

Introduction:-

Hello everyone,
I am Darksitecoder today I’m going to represent my blog on Object-Oriented Programming or we can say OOP’s programming, as I thought you are a programmer and you also studied about various types of programming language like, JAVA, C++, C#, Python, JavaScript, and many more in those languages we have a very powerful concept that is OOP’s concept in OOP’s we will talking about many things like, What is Class?, What is Object?, What are the main parts of Object Oriented Programming?, What is Inheritance, Polymorphism, Encapsulation, and Abstraction?. Object Oriented Programming follow the rule of procedural or step by step programming it has its own object. The object can be anything like a car, a bus, a cat, or a game player. Here you thought how a car or a cat can be an object don’t worry we discuss these things very briefly and easily.

To know everything about Object Oriented Programming please read the full article carefully.

What is Class?

In simple terms, we can say that a class is a blueprint that explains the nature of a future object. An instance is a specific object created from a particular class. Classes are used to create and manage new objects and support inheritance a key ingredient in Object Oriented Programming and a mechanism of reusing code. So a class is a very essential part of Object Oriented Programming.

What is Object Oriented Programming?

Object Oriented Programming is a commonly used programming paradigm. The early program was expressed step by step as a list of instructions. While this approach, called structural or procedural, was good enough to write simple applications, with growing complexity and size of the source code, there was a need for something more convenient. And that’s where Object Oriented Programming or simply OOP, step in. OOP solves a problem by creating an object that interacts with each other. An object can be anything, a dog, a game player, or some UI (User interface) element such as a button. It describes what a thing is and what it can do. This is done by writing a class, which is like a template or a blueprint, where you define its attribute and methods.

To bring the Object to life, you create its instance, set the attributes, and tell it what to do. What’s great about OOP’s is that you can create as many instances as you want without the need to implement a function for each of them. Object Oriented Programming allows writing code with none or minimal code duplication. This helps keep programs organized and working with them easier.

What are the main parts of Object Oriented Programming? : -

In Object Oriented Programming has 4 parts or we can say Object Oriented Programming has four pillars these are:-

  1. Inheritance
  2. Polymorphism
  3. Abstraction
  4. Encapsulation

In this blog, you will learn these topics very easily with the help of many examples.

What is Inheritance?

Inheritance in programming is incredibly important mostly to save our own time now we’re going to start with-class let’s say I wanted to create another class that was for the truck will I’d need some specifications like wheels, doors, and a driver name and as you can see we’ve got some very similar properties, in fact, they’re all the same so if we were writing these separately we’d have to write the code for the truck class you can notice here we have to write same code twice which is bad practice in programming so this is where inheritance comes in inheritance allows us to use properties of an existing class already so if I had a base class let suppose we made a base class vehicle I could have wheels, door, and a driver name and from that, I could create a car class which inherits from the vehicle, what is Inheritance well it means it gets all of these properties and methods immediately available to it and that means we don’t have to write extra code. Let’s take a very easy example of Inheritance, as you know we have many kinds of habits. Have you ever think about how we got this kind of habit?

I know many people said we get these habits from our parents, and we transfer some habits to our next generation. Yes, that’s the real-life example of Inheritance.

Types of Inheritance: -

As we discuss Inheritance, here we list out the types of Inheritance. So mainly there are three types of Inheritance:-

Single Inheritance: -

Single Inheritance means we have only one parent class and one child class which is inherited from its parent class.

In this image, it is clearly showing that class (B) is inherited from class (A) Now we look at this topic with the help of programming. I explain the Inheritance with the help of the Python language.

Single inheritance
Single inheritance


Multiple Inheritances: -

Multiple Inheritances means a child class has the two-parent class or we can say a child class derived from two-parent class for example: -

In this image, it is showing that there are two-parent class (A) and (B) and there is a child class called class (C) it means that class (C) is derived from class (A) and class (B), by this class (C) can use the properties of both classes.

Multiple Inheritance
Multiple Inheritance


Multilevel Inheritance: -

Multilevel Inheritance as simple as multiple inheritances like a child class is derived from its parent class and another child class is derived from the first child class. For example: -

In this, it is clearly showing that there are mainly three classes, class (A), class (B), and class (C). Class (A) is the main parent class and class (B) is inherited from class (A) and there are also shows that class (C) is inherited from class (B). So we can the class (B) is a child class as well as a parent class also.

Multilevel Inheritance
Multilevel Inheritance


What is Polymorphism?

Polymorphism in programming is a kind of a different way of thinking let’s say we have a bunch of code little block of code and we put in some kind of input and that gives us some kind of output it does something with the input now what if I put in a different kind of input like I2 here is that going to put out some output well no it isn’t because the code doesn’t expect that input different type so all of this is going to fall miserably and polymorphism takes care of that polymorphism is effectively writing three copies of that code or four or five just multiple copies of it and each version of it will take in a different input.

In programming language and type theory, polymorphism is the provision of a single interface to entities of different types or use of a single symbol to represent multiple different types.

Note: - It means to use a single type entity (method, operator, or object) to represent different types in different scenarios.

Practical video on Polymorphism in English

Practical video on Polymorphism in Hindi


What is Abstraction?

What is abstraction in programming well it’s a big fancy word that simply means every block of code or functional method that you write should do a bunch of stuff as we might expect but that stuff is relatively unimportant to the input and the output what do I mean by this well I just want to give in some input and I just want to get out some output I do not care what goes on here and that’s abstraction, abstraction simply means I’m hiding stuff away from the user or the programmer so if we think about this in terms of let’s say you’re in a big software development team and your job is to write the bits that gets data from the server and then it’s someone else’s the server and then it’s someone else to show the data on a screen so they’re going to communicate with you and say please go get this and you’ll say no problem I’ll go get it and off you go to the big bad world of the internet which returns you the data now the guy writing the display code doesn’t really care how you get the data he just wants to say to you get me some data and then it’s up to you to get that data however you do it , it doesn’t matter that’s the whole point this software guy doesn’t need to know how you get just simply go and get it from the internet and to get you of course return it to display guy an d that’s what abstraction is it’s hiding away functionally and when you do that you get this beautiful effect in programming which is everything starts to become a kind of modular so again like blocks we have say the view we have the database we have internet and we have some other guy on your team that doesn’t do very much and they can all kind of talk to each other because they know how to talk in terms of input and output so as long as your thing your bit of code accept a certain input and puts out a certain type of output everything can talk to each other and later on by this can easily any kind of data from your code and nobody knows that some data or some code can be removed from it.

Basically, abstraction means to hide unnecessary details or code from the user which shows your code messy and horrible.

Abstraction
Abstraction
The output of code

Abstraction output
Abstraction output

What is Encapsulation?

Basically, encapsulation terms define the terms of hiding your code or personalize your code. It means in terms of programming we write some code which we don’t want to show anyone, by this we can hide our secret code which is very precious for us. The term Abstraction and Encapsulation are some similar in nature because they both do the same thing to hide your code. But there is a difference is that if we hide our code with help of abstraction then the code can be accessible but when we use encapsulation then take help some keys to hide our code like mainly we have three types of key: -

  1. Public key
  2. Protected key
  3. Private key

From these entire keys, we only discuss private because the other two keys are mostly accessible easily but the Private Key only accessible by some kind of password or you can say if we don’t use a special method to call the class then we never see the class.

Let assume we have an encapsulated class named Programmer and I have to call the class so I use a special method to call the class:

Method: - print(emp._Programmer__pr)

We also called it to name angling method

The concept of the private key method is very practical we can’t talk much more but you can see my video on encapsulation I explain everything very clearly.

Practical video on Encapsulation in English

Practical video on Encapsulation in Hindi


Conclusion: -

So as you read my blog on What is Object Oriented Programming and you also see my practical videos on it so here is a short summary about the whole content. Basically, Object Oriented Programming is based on User infarction. In simple words, an Object Oriented Programming contains a class and all the functions are stored in this class. Object Oriented programming is based on object, fields, and functions. Next, we talk about parts of Object Oriented Programming as you know that OOP’s stand on mainly four pillars 1. Inheritance, 2. Polymorphism, 3. Abstraction, 4. Encapsulation. First, we discuss Inheritance with help of real-world example like I mention in the first paragraph I mention that Inheritance is like our habits which we get from our ancestors like it has a parent class and a child class and mainly Inheritance has three parts 1. Single inheritance 2. Multiple Inheritance and 3. Multilevel Inheritance. Single Inheritance means there is only a parent class and only a child class. Multiple Inheritance means there are two-parent classes and only one child class and the child class is inherited from both classes and the last Multilevel Inheritance means there are a parent class and a child class which inherited from first-class and there is also another class inherited from the second class. And next, we have Polymorphism so Polymorphism is it means to use of a single type entity (method, operator, or object) to represent different types in different scenarios. And we have an interesting concept Abstraction which means to hide unnecessary code from your data. Last we discuss Encapsulation which very important in Object Oriented Programming. Encapsulation means to use of a private key to hide your code very secretly like we use a special type of method to call the class for example: -
print(emp._Class name__pr).

Note: - For such kind of blogs please connected with Darksitecoder and if you wanted to know about the different types of topics related to Programming and Information Technology please leave a comment of your favorite topic and or otherwise you contact me in my contact page. 

Stay Connected with Darksitecoder
Thank You

Comments