I've recently inherited some code. It has a class called SystemConfig
that acts as a grab-bag of constants that are used across the code base. But while a few of the constants are defined directly on that class, a big pile of them are defined as properties of a metaclass of that class. Like this:
class _MetaSystemConfig(type):
@property
define CONSTANT_1(cls):
return "value 1"
@property
define CONSTANT_2(cls):
return "value 2"
...
class SystemConfig(metaclass=_MetaSystemConfig):
CONSTANT_3 = "value 3"
...
The class is never instantiated; the values are just used as SystemConfig.CONSTANT_1
and so on.
No-one who is still involved in the project seems to have any idea why it was done this way, except that someone seems to think the guy who did it thought it made unit testing easier.
Can someone explain to me any advantages of doing it this way and why I shouldn't just move all the properties to the SystemConfig
class and delete the metaclass?
Edit to add: The metaclass definition doesn't contain anything other than properties.