Open biosafetylvl5 opened 6 months ago
This should be doable. We can use <class>.__subclasses__()
to get a list of children classes that inherit from <class>
, Ie. (GeoipsList
).
We'd probably end up merging GeoipsCommand
and GeoipsExecutableCommand
into one consolidated GeoipsCommand
class. This will require some restructuring for non-executable classes which inherit from GeoipsCommand
(GeoipsList
), but shouldn't be too much of a hassle.
We should also consider moving some functionality from GeoipsExecutableCommand
to GeoipsList
and GeoipsGet
if applicable.
Description
Using standard UML notation, eg: -.-.- > (dashed arrow) means "implements" ----> (solid arrow) means "inherits from"
This is the current CLI Class organization:
This is my proposal:
Potential Benefits of Changing Structure
Using inheritance to track the structure
This would get rid of things like this:
which are "magic lists" used to track code. Instead inheritance could be used to auto-track things.
eg the above could become:
This would make code simpler, maintaining the codebase easier, and contributions easier for newbies.
Less code duplication
For groups of commands like
List
, a singular print to console function could be used to decrease code duplication.eg. in
GeoipsListUnitTests
the print-to-console functionality is in__call__
and is:Similarly, in
GeoipsListTestDatasets
the print-to-console functionality is also in__call__
and is:This code could be refactored into
GeoipsList
, inherited and called like this:This would be advantageous because:
Code structure should mirror functionality
This is an ideological take. Having code structure mirror functionality conveys the following benefits:
This would make
geoips list
(and similar cmds) proper executable commandsCurrently, these print the help for the commands. This functionality could be maintained, but this re-org allows for future capability to be added if need be.
Potential Drawbacks of Changing Structure
Methods would be inherited
If
GeoipsListTestDatasets
inherits fromGeoipsList
, it will inherent all the methods, and all the methods that are not name mangled would be callable.@jsolbrig is concerned about this. See https://stackoverflow.com/a/7456865 for thoughts on the issue, and benefits/drawbacks to privatization via mangling.