Background
Today, I see someone asking if a Python class has an attribute that is similar to a public property, which modifies the corresponding property of an instance, modifies the corresponding properties of all instances of the class, and then thinks that a class that uses an auxiliary singleton pattern solves the problem.
Ideas
Modifying an instance Another instance is also modified, which sounds like a singleton pattern, but only for one property, so you can borrow a helper class.
Code
Class Attr (): Attr = {} def __init__ (self): self.__dict__ = Self.attrclass Myclass (): def __init__ ( Self): self.attr = attr () @property def value (self): return self.attr.value @value. Setter def value (self, value): Self.attr.value = value
Demonstrate
In [the]: a = Myclass () in [1In]: b = Myclass () in [B.value]: A.value = 1In []: b.valueout[50]: []: A.V = 2In []: Alue, b.valueout[52]: (2, 2)
Feelings
Design patterns and their combinations are utilized.