Right now, properties are quite messy. I started some research on using mixins to clean those up.
My idea is to add separate mixin classes that represent the various properties and can be combined to classes. For instance:
FloatMaxPowerPropertyMixin
FloatMinPowerPropertyMixin
FocusPropertyMixin
SpeedPropertyMixin
BottomUpEngravingPropertyMixin
These mixins could be used to create the property classes used by the various drivers, e.g.:
PowerSpeedFocusProperty uses the base class plus the three property mixins
EpilogEngravingProperty uses the base class plus the focus, speed and bottom up engraving property mixins
I'd in fact try to remove most of the actual implementations and use driver-specific classes. By having most of the code organized in the mixins, the redundancy between the classes is still greatly reduced.
Another advantage of this is that we will have no more hierarchies between properties. Currently, property classes are stacked up using inheritance to combine various functionality in a single class without having to duplicate code. This doesn't work that well at the moment, e.g., the int and float power classes are redundant.
The major downside is that Java itself cannot do mixins. We'd have to add a dependency on a separate module (there are a few to choose from) to implement such a structure.
I believe that using mixinx is very much in the interest of the project. It reduces the required maintenance efforts, it eliminates all redundant code between the property classes, and it allows driver developers to extend the functionality by just throwing in another mixin into their properties.
To give an example from real life, let's have a look at #219. There, a new focus property is needed in addition to the existing (very much cumbersome and long) FloatMinMaxPowerSpeedFrequencyProperty in order to be able to configure the focus within VisiCut. To add this, code must likely be duplicated from the PowerSpeedFocusFrequencyProperty. This is far from ideal. The current workaround is to just use the latter class and set both min and max power to the desired power.
I am working on a refactoring of the current properties to eliminate redundancies as much as possible while polishing/finishing the implementation of #219. We can add mixins later on.
Right now, properties are quite messy. I started some research on using mixins to clean those up.
My idea is to add separate mixin classes that represent the various properties and can be combined to classes. For instance:
FloatMaxPowerPropertyMixinFloatMinPowerPropertyMixinFocusPropertyMixinSpeedPropertyMixinBottomUpEngravingPropertyMixinThese mixins could be used to create the property classes used by the various drivers, e.g.:
PowerSpeedFocusPropertyuses the base class plus the three property mixinsEpilogEngravingPropertyuses the base class plus the focus, speed and bottom up engraving property mixinsI'd in fact try to remove most of the actual implementations and use driver-specific classes. By having most of the code organized in the mixins, the redundancy between the classes is still greatly reduced.
Another advantage of this is that we will have no more hierarchies between properties. Currently, property classes are stacked up using inheritance to combine various functionality in a single class without having to duplicate code. This doesn't work that well at the moment, e.g., the int and float power classes are redundant.
The major downside is that Java itself cannot do mixins. We'd have to add a dependency on a separate module (there are a few to choose from) to implement such a structure.
I believe that using mixinx is very much in the interest of the project. It reduces the required maintenance efforts, it eliminates all redundant code between the property classes, and it allows driver developers to extend the functionality by just throwing in another mixin into their properties.
To give an example from real life, let's have a look at #219. There, a new
focusproperty is needed in addition to the existing (very much cumbersome and long)FloatMinMaxPowerSpeedFrequencyPropertyin order to be able to configure the focus within VisiCut. To add this, code must likely be duplicated from thePowerSpeedFocusFrequencyProperty. This is far from ideal. The current workaround is to just use the latter class and set both min and max power to the desired power.I am working on a refactoring of the current properties to eliminate redundancies as much as possible while polishing/finishing the implementation of #219. We can add mixins later on.