I am an advanced programmer who recently started using and learning python. I recently ran into this question. The answers in that question suggests that instead of using a static method inside a class, it is considered better design to just use a method and not use a class at all.
Code design 1:
gameResolution.py
width = 300
height = 300
# other variables, and functions following...
screenResolution.py
width = 1920
height = 1080
# other variables and functions following...
Code design 2:
resolution.py
class GameResolution:
width = 300
height = 300
# static functions following
class ScreenResolution:
width = 1920
height = 1080
# static functions following
As you can probably see, Code design 2 makes a lot more sense (in my opinion) in this situation. I could pack anything related to that entity (GameResolution or ScreenResolution for example) inside a class and all those classes inside a resolution.py file.
If I followed the Code design 1 I would end up with many tiny .py files, that would each represent a very small class. Correct ?
So, is it actually true that static methods are a bad approach for python ? In this situation, what would you do ?
widthandheightthe object attributes, and the methods non-static. Then you can create multipleGameResolutions etc.# other variables, and functions following...that do no match, so making aResolutionclass is not really possible. However since they do share a couple of common features it makes sense to keep them inside a common fileresolution.pyin my opinion, instead of making a douzen small.pyfiles