What is Really Object Oriented Programming?
Oops short for Object Oriented Programming is a programming paradigm (methodology) that uses data or objects to construct a logic rather than procedures or functions.
An object is more relatable to the real-life entities and that is why this approach is preferred over others for designing software applications.
A software is nothing but a virtual or a digital world that you can access with mobiles and computers.
To understand how OOP works,
Let’s first understand what are objects in real world and how do we communicate with these objects or
things.
Forget about the meaning of objects in terms of programming.
In real world object can be anything which has some size and shape and which physically exists, is tangible i.e., can be touch and felt.
So, at the time when you are reading this using a mobile, which is an object.
The thing on which you are sitting and reading is an object. Just move your eyes around in your room,
Anything and everything you see is an object!
The door, your bed, your wardrobe, the curtains, windows, fan, cooler, chair, table everything is an object! You are an object as well!
For Free, Demo classes Call: 8237077325
Registration Link: Click Here!
So, what is an object in real life?
Anything which has some physical properties is an object! It is that simple.
What do I mean by properties?
Anything you see has A colour.
A shape.
Is of some size.
Has some weight.
Is made up of some material.
Now these were some generic properties There are unique properties as well
Your Wardrobe Has doors
Handles to open these doors
Shelfs to store your clothing materials
Rods so that you can hang your clothes with a hanger A locker to store and secure personal belongings.
And if you observe closely
A wardrobe is not a single piece entity
It itself is made of these small objects which in totality and a defined structure makes it what looks like a wardrobe.
So, handles, shelves, doors are all objects as well.
Now these are unique properties because your chair doesn’t have a handle and your wardrobe doesn’t
have 4 long legs and arm support. Looking for C++ Training in Pune, SevenMentor is the best institute to head start your programming career in the field of IT.
So far, we have seen that an object has some generic properties that every object must have and some unique properties.
Now if you have these objects in your room it means they must be of some use to you!
Otherwise, you wouldn’t have them.
So, to use them, you interact with these objects.
- Window: open them when you want to feel the cool natural breeze.
- Curtains: pull them closer when you want some privacy.
- Chair: sit on it when you are tired or want to get some work done.
- Wardrobe: open the doors to store and get an item of clothing.
- Fan: turn it on when it’s hot, and increase the speed when it’s too hot.
So, every object you have in your house does something for you.
But to use the functionality of the objects, you need to interact with them.
Either you will walk towards it and use your hands or use a remote or maybe just a button to make use of the functionality when needed.
The point here is, objects are there and these objects are capable of doing certain things but only when you interact with them through some means.
To conclude what an object is in real world
An object has some properties.
An object is capable of doing certain things.
If we understand what an object is in real world then it is not so different in the virtual or the digital world.
As objects in real world are created through some physical process according to our need and convenience,
We can design objects in the virtual world as well according to our software needs and convenience.
Take an instance of the Zomato app Let’s see if we have objects in there Users that use it for ordering food?
Restaurant from which they order?
Food that is selected and added in the cart virtually?
The cart itself which is a collection of variety of food items? The Delivery guy who is selected to deliver it to you?
Every user, restaurant, food, the delivery guy is an object and there are thousands of these!
Objects are everywhere!
Let’s take a virtual object
Food
What are the properties of food on Zomato? The name of the food you see.
The category of the food which it comes under. The cost of the plate.
The amount it serves.
Are all the virtual properties you see
Now what do you do with it?
You can add a food item you like.
You can select the quantity of that food item. You can order that food item to your house. You can drop a review on that particular item. You can add toppings to it.
You can add cooking instructions to it for the restaurant! These all are the things you can do with a food object!
These are nothing but the methods that you can call on the food item.
So, objects behave in a similar way, let it be in the real world or the virtual world!
And if we design our software with this style of programming i.e., through objects, then it would be really easy and clean to map the real-world requirements of a company to a software application!
But how do we create these virtual objects?
In real world, the following process is followed to create an object.
- You first design how an object is supposed to look like meaning its shape, size, colour, the material,
it’s parts and subparts according to the functionality that is needed.
- Once you are ready with the final design of the object, it means this is how you want the object to be manufactured. So, this design or blueprint of the object is sent to a manufacturer. The manufacturer will construct the object according to the exact specifications mentioned in the design.
For Free, Demo classes Call: 8237077325
Registration Link: Click Here!
If you are going to a manufacturer, it probably means you don’t need just one object!
So, do you design again to create the same object? OfCourse not!
If the same object has to be manufactured again then it will have the same specifications i.e., it will have the same design.
So, you only have to design once and any number of objects can be created with it.
Let’s Consider an office chair and try to design it
Overview of specifications
Hard plastic frame.
Padded seats.
Cushioned back support. Padded arm rests.
Wheels.
Seat adjusters. Back adjusters. Colour all black.
Functionalities
Can sit on it with comfort.
Keep your hands on arm rest for support. Move around with the wheels.
Adjust the seat and back with adjusters according to your seating posture.
Note: to manufacture an object, you don’t need the functionalities. All you need are properties i.e
specifications of the chair.
Functionalities are mentioned here to understand what our object can do and why do we need certain properties like seat adjusters and wheels on our chair.
Functions are nothing but a way of accessing an object to get the object to do it’s specific task when
needed by the user. SevenMentor is the best training institute for C++ Classes in Pune with 100% placement assistance in the Top IT Companies.
Now once you send the design specifications to the manufacturer, he can construct n number of these chairs according to our requirement.
To conclude
- There is a design or blueprint of an object.
- And then there is the real object which is manufactured according to the design specifications.
So now that we have understood how objects are created in the real world.
Let’s try to understand how objects can be created in the virtual world!
As in the real world, we need a design or a blueprint before we actually create or manufacture an object.
Similarly, we need a design to create objects in the virtual world as well. We call this design or blueprint as a class.
A class has all the details and specifications of the object i.e. it has properties
+ it has functions or methods to access the object to make use of its functionalities.
Let’s create a design for our office chair but this time, the chair will be a virtual chair.
class Chair
{
int paddedSeat = 1; int backSupport = 1;
int paddedArmRest = 2; Int wheels = 4;
int seatAdjuster = 1:
int backAdjuster = 1;
moveChair(String direction, double distance)
{
will access the object and rotate the wheels in the specified direction till the
specified distance.
}
adjustSeat(String direction, double height)
{
will access the object and move the seat up or down according to the specified direction and height.
}
}
This is a virtual design.
To create a virtual chair object, you just need the properties mentioned in the first part of the class.
You don’t need the methods to create an object.
Please remember that methods are only ways to make use of the object.
So why do we need methods in a class if methods are not part of the design of an object?
Because these methods are specific to an object i.e. how can this object be used! it makes sense to group it together.
It is just like you get a manual when you buy something, and in the manual are the instructions to use it.
Similarly, you define the properties of how an object should be, in the class and write down the methods so that you can actually make use of this object.
For Free, Demo classes Call: 8237077325
Registration Link: Click Here!
To conclude
A class is a blueprint of an object.
A class consists of properties and methods.
Methods are used to access the object in order to make use of the functionalities of an object.
Question
is size of an object dependent on the number of methods you have in its class?
Author:-
Onkar Nagarkar
Call the Trainer and Book your free demo Class For C++ Call now!!!
| SevenMentor Pvt Ltd.
© Copyright 2021 | Sevenmentor Pvt Ltd.