Object Oriented Programming Overview
Object Oriented programming is a programming style this is associated with the idea of class, object and diverse other concepts revolving around those two, like Inheritance, Polymorphism, Abstraction, Encapsulation and so on.
Understand Object Oriented Programming with Real Life Example
Let us attempt to understand a bit more about the majority of object-oriented programming, via a simple example. Human beings are living things, extensively classified into two types, Male, and Female. Right? Its real. Each individual(Man or woman) has two legs, two arms, eyes, one nostril, one coronary heart etc. There are many body parts which are common for Male and Female. But then there are a few unique body parts, present in a Male which aren’t found in a girl, and some body components found in female however now not in men.
All human beings walk, eat, see, speak, pay attention and so forth. Now once more, both Male and female, plays a few familiar features. However, there are some specifics to each, which isn’t legitimate for the other. As an example, A woman can produce offsprings, even as a Male cannot, so that is best for the girl.
Human Anatomy is thrilling, isn’t it? However, let’s have a look at how all this is related to C++ and Object-Oriented Programming concepts. Here we are able to attempt to provide an explanation for all of the Object-Oriented Programming standards via this situation and later we will have the technical definitions for all this.
Class in above Scenario
Right here we will take Human Being as a Class. A Class in object-oriented programming is a blueprint for any purposeful entity which defines its attributes and its features. Like Human Being, having the body parts, and performing numerous actions.
Thinking about HumanBeing a Class, which has properties like fingers, legs, eyes and many others, and features like walk, speak, eat, see etc. Male and woman are also Classes, however maximum of the attributes and features are added in HumanBeing. Subsequently, they can inherit the whole lot from Class HumanBeing by using the concept of Inheritance.
Object in OOP
My name is Ayyaz, and I am an instance/object of class Male. While we say, Human Being, Male or female. We just suggest a kind, you, your friend, me we’re the varieties of those classes. We’ve a bodily life even as a class is only a logical definition. we are the Objects.
Abstraction manner, showcasing simplest the required things to the out of door for the world at the same time as hiding the details. Persevering with our example, Human Beings can speak, walk, hear, eat, but the information is hidden from the outside. We are able to take our skin as the Abstraction issue in our case, hiding the inner mechanism.
This concept is a touch complex to provide an explanation for with our example. Our Legs are bonded to help us walk. Our fingers, assist us to preserve things. This binding of the attributes to functions is referred to as Encapsulation.
Polymorphism is an idea, which permits us to redefine the way something works, through either converting how it’s far executed or by way of converting the parts the use of which it is accomplished. Each the methods have differing phrases for them.
If we walk with the help of our arms, and no longer legs, here we are able to change the parts used to carry out something. Hence this is called Overloading.
And if there’s a defined way of walking, but I desire to stroll in another way. But by using my legs, like absolutely everyone else. Then I will stroll like I need, this will be referred to as Overriding.