Update: Based on the code you have posted now, it's impossible to call is_ownable
on a MobileObject
because the MobileObject
doesn't appear to have a definition for is_ownable
.
If it does, then the difference is simply the difference between MobileObject
's definition and OwnableObject
's definition. I've updated the terms of the below to illustrate what I mean.
If you create a class in Python (or in any language, really):
class MobileObject(object):
def __init__(self, position):
self.position = position
def move(self, position):
self.position = position
def is_ownable(self):
return False
And then create a subclass:
class OwnableObject(MobileObject):
def __init__(self, position, owner=None):
MobileObject.__init__(self, position)
self.owner = owner
def is_ownable(self):
return True
def is_owned(self):
return self.owner
The resulting subclass automatically inherits the methods of its superclass:
movable = MobileObject()
movable.is_ownable() # returns False
movable.move(new_position) # moves movable
movable.is_owned() # causes an error
ownable = OwnableObject()
ownable.is_ownable() # returns True
ownable.move(new_position) # moves ownable
movable.is_owned() # returns owner or None
As you can see, is_ownable()
and is_owned()
differ between the two classes -- and in the latter case, since is_owned()
is not defined, it causes an error when called on movable
. But move()
works identically in both classes.