Referrers, Referents, Parents and Children

被刻印的时光 ゝ 提交于 2019-12-11 04:51:55

问题


I'm experimenting with the Dill package, specifically it's detect module and having some trouble intuitively understanding what's is meant by referents, referers, parents and children.

A reference is a value that enables access to some data.

And referents are objects that are referred to, right?

So in the following code:

class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'

an_instance = MyClass()
an_instance2 = MyClass()
an_instance3 = MyClass()

a_list = [an_instance, an_instance2, an_instance3]

Are an_instance, an_instance2, an_instance3 referents of a_list and would the MyClass also be a referent of a_list, but one level of depth further up the chain?

So, with -> signifying the reference, would the chain of referents look like:

a_list -> an_instance -> MyClass

Would this be viewed as:

grandchild -> child -> Parent

Conversely, is a_list a referrer of an_instance as well as an_instance2, an_instance3 and at another level of depth, MyClass?

Making the chain of referrers:

MyClass -> an_instance -> a_list

And would this also be conceived:

parent -> child -> grandchild

Can someone offer a clear explanation of where references, inheritance and containers do and don't coincide?


回答1:


In python, inheritance builds a pointer relationship between the class object and the class instance object. For example, a class instance first checks it's own __dict__ then points back to it's class definition to find any missing attribute. Similarly, instance methods can be seen as partials that are applied over class methods, again giving a pointer relationship to the underlying class method. With python, inheritance is little more than when an object can't find some attribute within itself it looks back to the parent (in the mro) for the missing attribute -- that hierarchy is built through a pointer relationship.

That's about the extent that inheritance and pointer references are the same. Pointer references are much more general.



来源:https://stackoverflow.com/questions/25651491/referrers-referents-parents-and-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!