Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Python objects originate from a common parent class?

Everything in Python is an object, and almost everything has attributes and methods. Now, according to Object Oriented Programming, every object created in Python must be an instance of a common parent class. However, this logic just doesn't make sense to me.

Can someone clear this up for me?

like image 392
Manas Chaturvedi Avatar asked Nov 19 '25 05:11

Manas Chaturvedi


1 Answers

according to Object Oriented Programming, every object created in Python must be an instance of a common parent class

This is not true. It happens that, in Objective-C, Java (and maybe C# too?), things tend to derive from a single superclass, but this is an implementation detail - not a fundamental of OO design.

OO design just needs a common-enough method to find the implementation of a method you wish to call on the object on which you wish to call it. This is usually fundamental to how the language works (C++, C#, Java, Objective-C, Python, etc all do it their own way that makes sense for their language).

In C++, this is done for static types by the linker and for dynamic types (through virtual inheritance) by a vector table -- no need for a common base class.

In Objective-C, this is done by looking up something in a hash-map on the object's class's structure, then calling a specific method to get the signature of the desired method. This code is nuanced, so everything generally derives from a single, common base-class.

Python technically shouldn't require this, but I think they've made an implementation choice to make everything be a class and every class derive from a common base class.

like image 156
iAdjunct Avatar answered Nov 21 '25 19:11

iAdjunct