Я хочу использовать возможность для нескольких подклассов совместно использовать один и тот же родительский класс. Как мне сделать это без вызова множественного наследования.
class Base(object):
shared_thing = 'Hello'
things = []
def __init__(self, message):
self.things.append(message)
class One(Base):
def __init__(self, json_message):
super(One, self).__init__(json_message)
class Two(Base):
def __init__(self, message):
super().__init__(message)
class Three(Base):
def __init__(self, message):
Base.__init__(self, message)
one = One('one')
print('ONE: ' + str(one.things))
one = One('one but a second time')
print('ONE: ' + str(one.things))
two = Two('two')
print('TWO: ' + str(two.things))
three = Three('three')
print('THR: ' + str(three.things))
base = Base('base again')
print('BAS: ' + str(base.things))
Однако, эти три разные инициализации super дадут мне ссылку на один и тот же объект
ONE: ['one']
ONE: ['one', 'one but a second time']
TWO: ['one', 'one but a second time', 'two']
THR: ['one', 'one but a second time', 'two', 'three']
BAS: ['one', 'one but a second time', 'two', 'three', 'base again']
Я не ориентируюсь на суперобъект с Python, поэтому извините, если это неправильный подход.
Спасибо!