September 2026
1051 pages
35h 4m
English
Sometimes it’s useful to manipulate access to the attributes of a class according to certain rules. For example, there are attributes for which only certain values make sense. In the Account class created earlier (Section 19.2.4), for example, there is the max_daily_turnover attribute, whose values should always be positive; otherwise, they wouldn’t make sense.
Setter and getter methods represent a concept of object-oriented programming for controlling access to attributes. Instead of accessing an attribute directly, access to it is controlled by special methods.
To keep the following example manageable, we’ll introduce a new class A that has an attribute managed via setter and getter ...
Read now
Unlock full access