User: Password:
|
Log in / New account

Refcounting and multiple inheritance

Refcounting and multiple inheritance

Posted Jul 11, 2011 19:51 UTC (Mon) by Auders (guest, #53318)
Parent article: Object-oriented design patterns in the kernel, part 2

> Though it seems obvious when put this way, it is useful to remember that a single object cannot have two reference counters - at least not two lifetime reference counters (It is fine to have two counters like s_active and s_count in struct super_block which count different things). This means that multiple inheritance in the "data inheritance" style is not possible. The only form of multiple inheritance that can work is the mixin style used by list_head as mentioned above.

The standard CPython implementation of Python uses reference counting, and yet it supports multiple inheritance. How is this possible?


(Log in to post comments)

Refcounting and multiple inheritance

Posted Jul 12, 2011 3:29 UTC (Tue) by neilbrown (subscriber, #359) [Link]

> The standard CPython implementation of Python uses reference counting, and yet it supports multiple inheritance. How is this possible?

A good question. I suspect that when you find the answer you will have a deeper understanding of inheritance.

I am not at all familiar with the CPython implementation or particularly familiar with multiple inheritance in Python so I cannot give a definitive answer. However as I noted in the introduction, "inheritance" does not seem to be a very well defined term, and "multiple inheritance" even less so. So the apparent contradiction could just be a confusion in the use of terms.

The short answer is simply that whatever CPython allows one class to inherit from multiple other classes, it cannot include the reference counters.


Copyright © 2016, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds