This question is related to this topic.
Context:
class OperationDevice(Device):
def __init__(self):
super(OperationDevice, self).__init__()
def operation_start(self):
# Do operation specific code
self.start()
def operation_stop(self):
# Do operation specific code
self.stop()
class SimulationDevice(Device):
def __init__(self):
super(SimulationDevice, self).__init__()
def simulation_start(self):
# Do simulation specific code
self.fsm.start()
def simulation_stop(self):
# Do simulation specific code
self.fsm.stop()
class DualModeDevice(OperationDevice, SimulationDevice):
def __init__(self, mode='simulation'):
super(DualModeDevice, self).__init__()
self._mode = mode
self._start_map = {
'simulation': self.simulation_start,
'operation': self.operation_start
}
self._stop_map = {
'simulation': self.simulation_stop,
'operation': self.operation_stop
}
def start(self):
self._start_map[self._mode]()
def stop(self):
self._stop_map[self._mode]()
Here I have to define in OperationDevice
and SimulationDevice
different method name like simulation_start
and operation_start
(because of MRO).
I actually want to define the same method name for both class and be able to call each one from
DualModeDevice
or subclasses. For exampleoperation_start
fromOperationDevice
andsimulation_start
fromSimulationDevice
will becomestart
. Is it possible and how?This solution is a way to switch between class
OperationDevice
andSimulationDevice
following value of mode. I am wondering wether is it possible to define automatically all method fromSimulationDevice
linked withmode = "simulation"
(same forOperationDevice
with"operation"
) without having to specify for each method (self._start_map
for example) in constructor (init) ofDualModeDevice
.