Stop Writing Classes
Why Code Review Stack Exchange recommends it
Code Review Stack Exchange commenters link it when reviewing code that wraps a single method or simple logic in a class and a plain function would do.
Recommended by 3 people across 3 different months, 2017 to 2021.
What it is
A PyCon talk (uploaded by HackersOnBoard) by Jack Diederich arguing that many Python classes are unnecessary and should be plain functions or modules. It runs about 27 minutes and uses examples of over-engineered class design.
What people said
Recommends Benjamin R · 2017-11 · Code Review Stack Exchange · on “Beginner object-oriented text-based RPG”
@EricLippert I would go further and question whether OO is really necessary at all. @WatCow what are you trying to optimise/solve by using OO? Keystrokes, code duplication (it's a fail on both, look how many times you are writing `public x y` for starters). Before you go too much further, I highly recommend checking out this great talk "Stop Writing Classes": [this video] You don't have to take it as gospel, but it's worth thinking about. The other question I would ask: Is Java the right tool?
Recommends AJNeufeld · 2020-02 · Code Review Stack Exchange · on “Linear Regression Class in Python”
Consistency Your class does not seem consistent with itself. If you create a LinearReg object: x = [1, 2, 3, 4, 5] y = [2, 3, 2.5, 4, 3.5] lr = LinearReg(x, y) The constructor computes the mean of the x and y lists, and stores these for later computations. These means are fixed; you cannot add additional data points, as the mean will not be recomputed. If you call lr.get_b_zero() , you will return the value 0 , since the b_zero member has not been computed. Each time you call lr.get_slope() , it recomputes the slope and stores the result. If you have changed the x and y lists, the computed value will be different ... and incorrect since the mean values have not changed. Each time you call fi
Recommends Konrad Rudolph · 2021-10 · Code Review Stack Exchange · on “Python password generator class”
Unfortunately your class with a single method isn't really much better, in terms of design, than OP's code. Both are pseudo-classes that should be replaced by regular functions. See *Stop writing classes* by Jack Diederich [this video] .