I’m working with some code left from other developers. Here we have several projects we can work with. The project object is instantiated at the runtime. Then it used in other classes. There are no methods in Projects and the class holds pure configuration values.
Is subclassing a proper way to define configuration for different Projects? Isn’t it better to create one class and get values from configuration file?
class BaseProject(metaclass=ABCMeta): """ abstract class for projects concrete version of this needed only to keep transition IDs in case of custom workflow. """ @property @abstractmethod def project_id(self): pass @property @abstractmethod def transition_id(self): pass @staticmethod def by_name(name): for prj in BaseProject.__subclasses__(): if name.lower() == prj.__name__.lower(): return prj() return Project3() @staticmethod def by_card_name(name): for prj in BaseProject.__subclasses__(): if name.split("-").lower() == str(prj.__name__).lower(): return prj() return Project3() # concrete projects class Project1(BaseProject): project_id = 12334 transition_id = 444 class Project2(BaseProject): project_id = 4451 transition_id = 88 class Project3(BaseProject): project_id = 12346 transition_id = 88
It looks good in term of open/closed principle. But I’m a little confused that values are in classes themself not in configuration.
BTW we don’t expect any more projects in future and existing are hardly to change.