In python, during a recent code review, it was pointed out that using classmethods and staticmethods is considered a bad practice because it enlarges the scope of the given class.
In the specific case, it was suggested that a factory method could become a classmethod as an alternative constructor:
class FooConfig:
...
class Foo:
def __init__(self, x: int):
self.x = x
def create_foo(c: FooConfig):
f = Foo(c.x)
return f
could become
class FooConfig:
...
class Foo:
def __init__(self, x: int):
self.x = x
@classmethod
def from_config(cls, c: FooConfig):
return cls(c.x)
and senior members rejected it saying that classmethods and staticmethods are bad practice because they enlarge the scope of the class. I’d like to understand if that is indeed the case.
Hsflores is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.