I am trying to wrap my head around multiple inheritance and contrived a very simple example that is not able to access all of the inherited attributes. This may or may not be possible, but if so I could use some help. Here is how my code is structured along with some comments.
I made a Status class with a single attribute (status). The idea is that all of the other classes can inherit from status and thus get the status attribute.
class Status():
def __init__(self, status: str = ""):
self.status = status
Now I will make a class 'A' which inherits from Status and adds some methods to connect or disconnect from something.
class A(Status):
def __init__(self):
super().__init__("Disconnected")
def connect(self):
if self.status == "Disconnected":
print("Connecting A")
self.status = "Connected"
else:
print("A already connected, doing nothing")
def disconnect(self):
if self.status == "Connected":
print("Disconnecting A")
self.status = "Disconnected"
else:
print("A already disconnected, doing nothing")
This seems to work. In my test code, I can instantiate an instanse of A, call the new methods as well ass access A's status.
print('\n***Class A**')
a = A()
print(a.status)
a.connect()
print(a.status)
I then repeated this process and made a very simple class (B) which also inherits from Status. Following similar test code as before, I can instantiate an instance of B and access its status.
class B(Status):
def __init__(self):
super().__init__("B Uninitialized")
Now I would like to make a new class 'Composite' that inherits from A, B, and Status
class Composite(A, B, Status):
def __init__(self):
super(A, self).__init__()
super(B, self).__init__()
super(Status, self).__init__()
self.status = "Composite Uninitialized"
This "works" as composite can read/write its status (inherited from Status) as well as call the methods inherited from A. However, I would also like to be able to access the status of the A and B objects in addition to composite's own status. It seems this should be doable, but I cannot figure out how. Thanks!!