Question about class an object

Can I see class as an abstract specification while object
as an actual thing that follows the specification. As “class
is like a blueprint, while object is the actual thing”

Yes. The object is what is returned when you instantiate a class. You can instantiate a class as many times as you wish, but each object that is created is an ‘individual’: they reside in their own memory area and have their own data.

That’s basically it, but, as with many things in computers, a large majority of OOP is just made up terminology that is only used in OOP. A few words that pop up are:

instantiate – Basically a fancy way of saying “create” or “make”. You can’t say “make a Sandwich”, you have to “instantiate a Sandwich”.

method – It’s important that you realize that doing is so totally different from foo(bla, stuff) that you need two different words. Never mind that most languages translate into a call to foo(blah, stuff). What’s important is that you call the first one with the dot a “method”, but the other one that works the same is called a “function”.

instance – An object is an instance of a class after you instantiate it from the class, and also don’t forget that class is an instance of some other class that you didn’t have to instantiate because your OOP has a meta-class that is added to the class so that it’s not an instance of the meta-class but it’s more of a…like…I think it’s just a class. Basically, if you use a recipe to make a Sandwich then the recipe is the class, and the Sandwich is an instance after you instantiate it. However, your recipe is also an instance of something too.

MRO – Method Resolution Order. Basically multiple-inheritance is so complicated that there needs to be a fixed set of rules that determine how a function is found in a class hierarchy. There’s a fairly standard one that most every language uses, and I believe Python originally got this wrong, which is why Python 2.x has an object class.

attribute – A variable that’s described in a class and then setup in your __init__ when you make (instantiate) an object.

member – A thing in a class that is available in an object when you make one. This can be function…I mean methods, and variables…I mean attributes.

class – It’s basically a dictionary with attributes (variables) and methods (functions) that gets copied or linked to a new object and configured with your init method when you make one. Do this sometime:

>>> class Stuff: pass
>>> Stuff.__dict__
mappingproxy({'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Stuff' objects>, '__weakref__': <attribute '__weakref__' of 'Stuff' objects>, '__doc__': None})
>>> x = Stuff()
>>> x.__dict__
>>> x.__class__.__dict__
mappingproxy({'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Stuff' objects>, '__weakref__': <attribute '__weakref__' of 'Stuff' objects>, '__doc__': None})

It’s kind of weird because there are people who actually say a class isn’t a dict, and then, well, it even has a __dict__ attribute (variable) which defines what’s in the class, and then the objects have a __dict__ that does the same thing.

Anyway, hope you enjoy the snarky light humor.

1 Like