[Tutor] Inheriting from parent object

Alan Gauld alan.gauld at freenet.co.uk
Mon Nov 14 21:17:44 CET 2005

> I want to create a property that will inherit it's value from the same
> property in it's parent object, but will check it's parent's propety
> everytime it is called.  But that can be over-ridden, and I don't have
> to know what the objects parent is.

Ed you are using a lot of OOP terminology here to decribe 
something that looks decidedly non OOP. Can you clarify exactly 
what you mean by the terms:
    object, property, inherit and parent.

Also can you describe the problem you are trying to solve rather than 
the solution you think you need? It may be that there is a simpler 
paradigm you can use. I'm not sure I really understand what you 
are trying to achieve.

> object.x = 3
> object.subobject.x = inherit()
> print object.subobject.x #prints 3
> object.x = 4
> print object.subobject.x #prints 4
> object.subobject.x = 5
> print object.subobject.x #prints 5

object it the built-in object class that provides new-style classes, 
is that theone you are using here? Or is it just a generic name for 
illustration? Is object an instance or a class?

> What could I put in the inherit() function that would look for the
> same property of it's parent and return that, whilst keeping it as
> general as possible?

I also don't understand what the inherit() function is supposed to do. 
You provide it with no context in which to operate. 
Unless it relies on hard coded global variables there is no 
way it can know about object, subobject or x.

Normal OOP inheritance relies on creating instances from classes, 
but you don't appear to want to do that, it looks more like you 
are building some kind of containment lattice. I think I need more 

Alan G
Author of the learn to program web tutor

More information about the Tutor mailing list