Login
Theme: Light Dark

What are the differences between class, attribute, and instance in OOP?

Tagged:

Home - Quora Link

OOP stands for ‘object oriented programming’. What are these objects and why do these languages orient around them?

The idea of an object is actually pretty simple, it makes it so you can deal with data and behavior at the same time. Object-orientation means that the execution context will largely revolve around objects and not data or behavior. Functional programming dispenses with the connection and deals with data and behavior separately.

So, objects need to have patterns in order for us to be able to reason usefully about them. You need to know what kinds of data they hold, and what kinds of behaviors they exhibit. Wrapping all this together gives you the object’s class. A class generally defines two types of things, attributes and methods. Attributes determine the object’s data, while methods determine it’s behavior.

Objects are instantiated so they can be used. This instantiation sets the values of the attributes, you can think of an instance as a version of a class that has its attributes set.