Closed romeroyonatan closed 5 months ago
In the pattern Accessing a protected member from outside the class could be use properties a best practice?
For example
class Rectangle(object): def __init__(self, width, height): self._width = width self._height = height @property def width(self): return self._width r = Rectangle(5, 6) # access from property print("Width: {:d}".format(r.width))
In this way, we ensure read-only access to member and avoid side-effects because the assignment is not allowed
In the pattern Accessing a protected member from outside the class could be use properties a best practice?
For example
In this way, we ensure read-only access to member and avoid side-effects because the assignment is not allowed