Object vs Instance - What's the difference?
Object-Oriented programming can be a bit confusing at times as there are concepts with very minute differences. The worst thing is that the more you read, the more you get confused as 100 people have 100 interpretations of the same concepts.
When you can verify something physically and explain it in the simplest possible explanation, that concept can be said to be cleared.
Coming back to the question, Objects and Instances are almost similar and are often used interchangeably but with a small difference.
Let's take a Story. Suppose You are God and You are given the task to make a new species called Males. So you start designing your species. All the males will have hands, legs, eyes, nose, etc. These features/states can be called attributes/properties. All males can run, walk, talk eat, etc. These are the behaviors/functions of males and can be called Methods.
Once you have designed the properties and behaviors of your new species, Your class is ready. So basically Class is a design on paper ( a blueprint) that how the males would look and how would they behave.
Males don’t exist in reality so far, they are just a concept.
Now God started making Males in reality (Physical manifestation). So he started looking at the blueprint and created a male. When he created a male, in reality, that male needs to have a space to live, so a space on Earth is reserved for that male to live.
Here the act of making physical manifestation, the act of making a male is creating objects from the class. The act of giving space to males is creating a memory for the object.
Now there is a small problem encountered by god, he can create n numbers of males all identical and give them space on earth to live but how can you identify and differentiate them.
What if God wants one of those males to do something. How will he command? How will he refer him?
Here comes the concept of Instances. He took one of the males and gave him the name Nobita. So now that object (male) has a reference called Nobita. The location given to him to live can be said as Nobita’s location.
The object is a generic term, it is physically present but remains undifferentiated. The instance is something that gives them a separate identity.
Talking in terms of Code (in Python )
When we create an Object; ex:
Nobita = Males(“blank”,0)
Here when you write Males(..), an object is created and the name which refers to that object (Nobita) is called an instance of that object.
Hope it clears the confusion. Tell me in the comments if you have any doubts or any suggestions.
Explained beautifullyπππ
ReplyDeleteVery very thank you sir
ReplyDeleteWell done!
ReplyDeleteMaaan you are a life safer ππππππ
ReplyDelete