I want to model a machine with a class machine
. By the way the architecture of the project has been built, the module that defines each machine is its own directory. So in directory manufacturer/machine_111/
there is a file machine.py
Class Machine(ModelX):
def __init__(self):
....
def do_something(self):
...
Each machine can inherit common behaviour form by being of the same model. So in manufacturer/models/
there is 'modelX.py`
Class ModelX(BaseMachine):
....
It also inherits from the BaseMachine
class in the main directory of the project.
My problem is that for some machines I don't have special behaviour to inherit from the ModelX class. And some other machines are fine to be modelled with the BaseMachine
class.
My goal is not to have to write the machine_111
module (or the modelX.py
if it is not needed.
In sumary, I want to be able to write something like this:
a_machine = BaseMachine() # if there is no `modelX.py` and `model_11.py`
a_mahcine = ModelX() # if there is not `model_11.py` but there is `modelX.py`
a_machine = Machine() # if `model_111.py` exitst
but the inheritance chain should be different. If modelX.py
, 'Machineinherits from it, and if not in inherits directly fomr
BaseMachine`.
What tools and design patterns can I use?
Aucun commentaire:
Enregistrer un commentaire