I'm having some trouble keeping apart the terms class, object, variable and datatype.
can a class be considered as a datatype? can an object be considered as a variable?
Also, what's the technical difference?
Simple variable can only hold one value (string, number, boolean etc). Object can hold pairs of variables and values, also that object model can be used for another object just different values, and oop is based on that, using same code multiple times with diff value s without rewriting it.
The variables that the object contains are called instance variables. The methods (that is, subroutines) that the object contains are called instance methods.
An object variable or instance member belongs to a specific instance of a class. That is to say that every instance has its own copy of that piece of data. A class variable or static member is shared by every instance of the class.
Object (a.k.a. value): a "thing". Lists, dictionaries, strings, numbers, tuples, functions, and modules are all objects. "Object" defies definition because everything is an object in Python. Variable (a.k.a. name): a name used to refer to an object.
There are two different uses of these terms:
Casual use:
C/C++ standard use (comes from the C standard, which isn't an Object-Oriented Language:
Variables are objects with direct names.
int i;
i is a variable and an object.
int* p = new int;
*p is an object but not a variable.
Classes and types are pretty much identical, except types includes primitive types like int. Realistically, they're pretty interchangable- as well as variable/object. The reality of the C++ Standard is that very few rules apply differently to classes than to types, and variables than to objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With