Good day. The question arose how good practice is to use a class variable as a kind of global variable?
Let me explain with an example. For my one task, I had to create a class whose objects would receive a unique number when created. I did it like this:
class A(object): _counter = 0 def __init__(self): self.id = A._counter A._counter += 1 It works, but how good is it in terms of the correct principles of architecture?
This is something very similar to a global variable.
But it can be done to make instances of an object not only received students in such a way, but then communicate with other instances through class variables. How right to do so?
And if we put in a variable not just a value, but a complex object, then it will generally turn out to be a singleton.
And not only its instances, but also some external code can access a class variable. So, probably, you should not do at all?