I have a class that I use to define different types of plots I am performing
class MyPlots(Enum): STANDARDSCALE = "standard" LOGSCALE = "log"
there are default values associated with the coordinates I usually plot with, i.e., in my code I have parts like
... if self._plottype==MyPlots.STANDARDSCALE: xlimits = [math.e, math.e**2] if self._plottype==MyPlots.LOGSCALE: xlimits = [1,2] ...
I am wondering about what would be the best way to refactor this code, i.e., writing an abstract class
class PlotTypeWorks(ABC): xlimits @virutalmethod def __init__(self, type : MyPlots): """ Sets limits """ class Plot(PlotTypeWorks): def __init__(self, type : MyPlots): self._plottype = type if self._plottype==MyPlots.STANDARDSCALE: self.xlimits = [math.e, math.e**2] if self._plottype==MyPlots.LOGSCALE: self.xlimits = [1,2]
I want the code to be fast and easy to read at the same time. What I am concerned about, is that with different classes (
PlotLog) the code might soon be overcrowded with plots with different parameters (hard to read). From the other side, with only one class, I might be calling a lot of checks (
if self._plottype==X) that might just slow my code when I will create thousands of those classes.
Is there a solution with the perks of both? i.e., less checks and more readability?