How many private variables are too many? Encapsulating classes? Cool practice?

Okay, that's why I'm currently working on a built-in statistics package for python, which is mainly focused on a combination of working with the arcgis geoprocessor, to simulate comparisons and tools.

In any case, I have one class that computes statistics. Allows you to simply call it "Statistics". Now my Stats class comes to the point that it is very large. It uses statistics calculated from other statistics to calculate other sets of statistics, etc. This results in a lot of private variables that are stored just to prevent recounting. however, there are certain ones, although they are used quite often, they are often used only by one or two key subsections of the functionality. (e.g. summation of matrix diagonals and probabilities). However, his beginning to become a serious eye, and I feel that I am doing this terribly wrong.

Is it so bad?

I was recommended by a colleague to just start investing basic and general functions in the main class, and then just have capsules that belong to the main class, and just do what they ever needed in themselves, for example. to calculate the accuracy of model predictions, I would create a capsule that simply takes a reference to the parent, and it will unload all the necessary calculations for model predictions.

Is something like this a really good idea? Is there a better way? Right now I have over a dozen different statistics that are dumped into a text file to make a small report. The code base is growing and I would just like it if I could start cracking more and more of my python classes. I'm just not sure what the best way to do things like this.

+3
4

. :

StatisticType = enum('AveragePerDay','MedianPerDay'...)

:

class StatisticBase
....
class AveragePerDay ( StatisticBase )
...
class MedianPerDay ( StatisticBase )
...    

" ", , , , , , .

+1

, , , ? . , , ?

, , . , python. , , , . , , .

+1

- , " " ( ), " " ( " " " -), - .

(DPs short_) , , , " " ( DP- "" ): , , , , , .

, , , , , " " ( , Python ).

, , ( , Creational , , , " " - . DP, ).

0

, pylint (http://www.logilab.org/857). , , .

0
source

Source: https://habr.com/ru/post/1734719/


All Articles